How can I ask the user for elevated permissions at runtime?

后端 未结 4 1175
小蘑菇
小蘑菇 2020-12-29 15:01

Some applications, started with a regular user will ask for elevated permissions when necessary (e.g. a file manager needs to write such folder), and then carry on with the

4条回答
  •  北海茫月
    2020-12-29 15:22

    In a nutshell: Create two executable files for windows. The regular executable, and a worker exe file that you use to perform "elevated" operations (by passing command line options).

    To the second EXE file you add an application manifest file with a node.

    When launching the worker app, make sure to use the QT function that wraps ShellExecute, NOT CreateProcess as CreateProcess simply fails to launch requireAdministrator apps, whereas ShellExecute (Being a shell function) can perform the UAC elevation prompt.

    It is also possible to do this with ActiveX controls, but as you are targeting Qt that seems less appropriate.

提交回复
热议问题