Reputation: 5525
I have an application which is a launcher for another application (my main one). The launcher goes to an FTP server, downloads updates and installs them. However, the update executable needs to copy some DLLs and EXEs to the installation directory of the main application, which is in Program Files. Because of that, I currently need to elevate the rights of the updater.
This is a problem because my application starts on boot, and in general will simply load to the system tray (the application is comparable to messenger/skype). If I start popping UAC warnings on the screen while trying to "silently" update the application, it's not so silent any more.
The only way I see right now to avoid the problem is to give all users permissions to the program files installation directory, but I am reluctant to do that. Any other ideas?
I'm using Windows 7, and the applications are in C#.
Upvotes: 7
Views: 6127
Reputation: 14373
I upvoted the accepted answer, because it is the correct one, but, sometimes we do need to eat our cake and have it too.
I found this tool to work beautifully from batch files or from startup:
https://github.com/alexey-gusarov/elevate
Can be installed via chocolatey:
choco install elevate
Upvotes: -1
Reputation: 7173
The whole point of UAC is that apps can't make priveleged changes without the user's approval. Rather than attempting to auto-update your app, perhaps you could simply let the user know that an update is available, and wait for them to ask for it to be updated (at which point the UAC prompt will be expected, as many apps update this way).
Upvotes: 2
Reputation: 564403
Doing so would violate the basic principle of User Access Control.
There is no way to elevate permissions while avoiding the prompts, by design. If there was a way to do this, UAC would become useless.
That being said, you could try to design around the issue. Instead of making your program a startup/system tray application, you may want to consider making a windows service that does the update. This could run as an administrator on boot (instead of login), and it would already run with elevated permissions.
If you need a system tray application, it could be a separate app that "talks" to the service.
Upvotes: 13