Posted by: Christian Wimmer in: JEDI Windows Security Code Lib
Many people add a “requireAdministrator” manifest to their Application to elevate their application in Vista. However itis not needed all the time so there is a second way that allows to elevate the program 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 an exception if anything goes wrong. The exception error constant E_USER_CANCELED_OPERATION reports that the user has canceled the elevation.