I am developing an application in Visual C++ 2010, and the application is targeted to Windows 7. There is a task of writing some values to registry that will happen only in some special cases. And since in Windows 7, it is needed to have administrator privileges for doing so. How could I program my application in a way, that when it is needed for doing such actions, it asks for administrator privileges and it would not ask for administrator privileges at start time.
Thanks.
I am developing an application in Visual C++ 2010, and the application is targeted
Share
Like Mark said, you cannot elevate your privilege on demand. A quick solution would be to write a separate executable that does the writing part and launch it using specific commandline parameters when you need. Of course this executable would have to have the ‘requireAdministrator’ privilege in its manifest.
You can also design this program as a service and setup an IPC mechanism, say using a named pipe. The pipe itself could be created with a security descriptor that allows normal user access to it ensuring that the program running at lower privilege will be able to write to it.
The purpose of the second approach is to eliminate the nasty UAC prompt that would appear with the first solution.