6

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#.

Eldad Mor
  • 5,405
  • 3
  • 34
  • 46
  • 3
    Use a scheduled task, you can run them with an admin account. The bypass is that it takes an elevated account to create them. – Hans Passant Nov 23 '10 at 18:34

4 Answers4

14

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.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • Thanks. I think it was clear from my question that I'm trying to eat the cake and leave it whole, as I don't want to break UAC yet I do want silent updates. I do like the service solution a lot, though. I might go for that solution indeed. – Eldad Mor Nov 24 '10 at 07:40
3

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).

JaredReisinger
  • 6,955
  • 1
  • 22
  • 21
0

As others have said UAC is to prevent this type of behavior, however you may be able to disable UAC then enable UAC post installation as I am assuming your "users" are local to your business. You could push this to a batch file and execute it using psexec as I believe you can do that remotely without installing anything on the client machine.

Disable UAC

C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f

Enable UAC

C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 1 /f
Aaron McIver
  • 24,527
  • 5
  • 59
  • 88
0

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
Ishmaeel
  • 14,138
  • 9
  • 71
  • 83