05 Apr
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.
2 Responses
Chris
23|Nov|2011 1This method will not show the “shield” icon in the executable, making it less optimal than the manifest method.
Christian Wimmer
23|Nov|2011 2It depends what are you’re going to do.
If you create your app to run as admin all the time because it needs to be, well then you can use the manifest approach.
However, an app shouldn’t be designed in this way. On the other hand, in some situations the whole app must be started as admin from the non-admin app, e.g. using a cmd line switch.
A good example is the Process Explorer from sysinternals.com. You can use this application as a normal user and see all your processes. However, to see processes from different terminal sessions and to get all their properties you have to restart the app as admin. You can do this by menu or calling the app directly from command line: procexp /e
A shield on the app icon is not a seal of quality – Far from it!
Leave a reply
You must be logged in to post a comment.