05 Apr
Posted by: Christian Wimmer in: JEDI Windows Security Code Lib
Many people add a “requireAdministrator” manifest to their Application to get elevation in Vista. However this is not needed all the time so there is a second way that allows to elevate even in Windows XP.
The solution is to restart the application with ShellExecute and the “runas” verb. In Vista you’ll get the elevation prompt, on XP (or if UAC is disabled) you’ll get a logon dialog that allows the user to type in Administrator credentials.
The following code executes the same application a second time, but does the trick with “runas”. JwShellExecute raises and exception if anything goes wrong. The exception error constant E_USER_CANCELED_OPERATION reports that the user has canceled the elevation.
Leave a reply