Need to elevate permissions without UAC pop ups

前端 未结 4 1048
野的像风
野的像风 2020-12-20 22:13

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

相关标签:
4条回答
  • 2020-12-20 22:20

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

    0 讨论(0)
  • 2020-12-20 22:25

    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
    
    0 讨论(0)
  • 2020-12-20 22:33

    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.

    0 讨论(0)
  • 2020-12-20 22:34

    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
    
    0 讨论(0)
提交回复
热议问题