Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ask Vista for system privileges

0 views
Skip to first unread message

Erick Engelke

unread,
Feb 5, 2007, 1:45:56 PM2/5/07
to

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 er...@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

David Lowndes

unread,
Feb 5, 2007, 5:51:25 PM2/5/07
to
>I want to ask Vista to run my application with Administrator privileges.
>...

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

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

Uwe Sieber

unread,
Feb 6, 2007, 3:05:35 AM2/6/07
to
Erick Engelke wrote:
>
> 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.


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

0 new messages