views:

2620

answers:

2

I think the title says it all. How can my vbscript detect whether or not it is running in a UAC elevated context?

I have no problem detecting the user, and seeing if the user is within the Administrators group. But this still doesn't answer the question of whether the process has elevated privs or not, when running under Vista or Windows 2008. Please note, I need only to detect this status; not attempt to elevate or (err ..) de-elevate.

Thanks for any thoughts you can add!

+3  A: 
quux
Of course this sucks. It would be cleaner to have access to the GetTokenInformation API. But apparently that's out of bounds for VBscript. Oh well - we do what we can.
quux
+1  A: 

The solution I am posting is a couple production ready VBScripts that leverage whoami to find this information. One cool thing about them is that they work with XP (for information that is available on XP) if you place a copy of the Resource Kit version of whoami.exe next to the script (or in the system32 folder of each machine).

CSI_IsSession.vbs contains a single function that can tell you almost anything you want to know about UAC or the current session the script is running under.

VBScriptUACKit.vbs (which uses CSI_IsSession.vbs) allows you to selectively prompt for UAC in a script by relaunching itself. Has been designed and debugged to work under many execution scenarios.

Both scripts contain sample code that demonstrates how to use the core script code.

Darwin
Wow, you really researched this! The blog article at your CSI_IsSession.vbs link is packed full of good info; thanks for that. It's still a bummer that vbscript can't do this without a call to whoami.exe, though.
quux

related questions