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.

Comments (2)

  1. Eric W says:

    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?

  2. Running an app named setup.exe does not bypass UAC – you’ll still be prompted to run the app.

Skip to main content