Welcome to MSDN Blogs Sign in | Join | Help

Programmatically determine if an application requires elevation in Windows Vista

In Windows Vista, by default, application will execute without administrator privilege, even when the user launching the application is part of the administrators group.

You can explicitly elevate the application with administrator privilege using the shell "Runas" verb.

There are some cases the OS will decide to launch the application as elevated by default. The decision points are:

1. If the application has a manifest that explicitly asks for administrator privilege. 
2. The application is one of the well known setup installers.  
3. Application Compatibility testing reveals that the application requires admin privilege.
4. A certain heuristics to determine if the application is an installer. For example, if the application name contains "setup" or "installer", it is a good indication that the application is an installer, thus requires administrator privilege.

There are times you may want to know if the OS will decide to launch the application elevated. For example, you may want to warn user before launch the application.

There is no direct API for this. But there is an alternative way to determine so:

Call CreateProcess() with dwCreationFlags as CREATE_SUSPENDED. If the application requires elevation, CreateProcess will fail, and GetLastError() will return ERROR_ELEVATION_REQUIRED.

Published Wednesday, October 18, 2006 8:00 AM by junfeng
Filed under: ,

Comments

# re: Programmatically determine if an application requires elevation in Windows Vista

Wednesday, October 18, 2006 1:20 PM by Eric W

If all I have to do as a virus writer to avoid UAC is name my exe "setup.exe", what exactly is this tech gaining anyone?

# re: Programmatically determine if an application requires elevation in Windows Vista

Tuesday, November 14, 2006 12:07 PM by michael_HOWARD

Running an app named setup.exe does not bypass UAC - you'll still be prompted to run the app.

New Comments to this post are disabled
 
Page view tracker