How to ask for Administrator privileges in Windows 7?

与世无争的帅哥 提交于 2019-12-10 20:03:00

问题


I wrote an application using Qt under Windows 7. The application starts up with normal user privileges, but I want to gain the Administrator privileges because I want to modify the registry to auto-start the application.

How could I do this?


回答1:


Take a look at the MSDN sample: UAC self-elevation (CSUACSelfElevation)

Also, Wikipedia actually has a pretty good reference including information on the ShellExecuteEx() "runas" verb and application manifest for elevation requests.




回答2:


You should embedd correct manifest to your exe:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx.

I know, you said using win32 API, but consider this standard and recommended way.




回答3:


You do not need administrator privileges to autostart your application.

Simply write the appropriate keys to:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

which does not require administrator privileges (unlike the same path under HKEY_LOCAL_MACHINE).




回答4:


Note that privileges cannot be changed while the program is running. It has to be killed and restarted with the correct privileges.




回答5:


to auto-startup the application, you don't need admin rights! Instead of adding the registry key under HKLM (where you need admin rights), use HKCU and you're fine.




回答6:


To make an application auto start in HKLM, the administrative privilege is needed. But the privilege of an application could not change while running.

So I made a new small application whose task is only write the registry to make the main application auto start.

The main application could call this application with ShellExecuteEx to require administrative privlege.



来源:https://stackoverflow.com/questions/11199430/how-to-ask-for-administrator-privileges-in-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!