- ask Vista for system privileges
- Posted by Erick Engelke on February 5th, 2007
I want to ask Vista to run my application with Administrator privileges.
I have a Win32 program which starts and stops a service (loaded as a
resource file).
People often download/run the file from a web browser, which works great
in XP, 2K, 2003, but in Vista I've been telling them to right-click and
run as Administrator so it can work.
I'd prefer to have my application ask Vista to run with escalated privs,
like RegEdit does, so the user doesn't have to in a special mode and just
gets asked by the OS if it should allow the program to run.
Thanks
Erick
Erick Engelke erick@uwaterloo.ca
Manager of Networks and Systems Integration PHY-3013
Engineering Computing (519) 885-1211 x35893
University of Waterloo http://www.eng.uwaterloo.ca/~erick
- Posted by David Lowndes on February 5th, 2007
Erick,
If your application needs to run as the administrator it should have a
manifest resource to indicates this.
If you add the following information to any existing manifest file in
your project it will cause Vista to prompt appropriately to have your
application run as the administrator:
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
For more information on the subject try Googling for the terms:
requestedExecutionLevel and requireAdministrator.
Dave
- Posted by Uwe Sieber on February 6th, 2007
Erick Engelke wrote:
Self restart you application by means of ShellExecute and
the "runas" parameter:
if ( ! IsUserAnAdmin() ) {
char szAppPath[MAX_PATH];
GetModuleFileName(NULL, szAppPath, MAX_PATH);
ShellExecute(NULL, "runas", szAppPath, lpCmdLine, NULL, nCmdShow);
return 1;
}
Uwe