|UPDATED: CSI_IsAdmin: Test for Admin Rights - Fast, Small, Efficient, Universal Script Code in VBScript (VBS), PowerShell (PS1) and CMD/BAT|
This script code uses a fast and efficient method for determining whether the current session (process) has admin rights. The compact code is provided in VBS (9 lines) and CMD/BAT (3 lines). It works with XP / Server 2003 through Windows 7 / Server 2008. It works with UAC (reports admin rights only if session / process elevated). It uses passive methods to determine rights – in other words, it does not try to change anything on the target system.
This script is a quick and universal method – unlike the CSI-Toolkit VBScript CSI_IsSession, it cannot tell you that the user COULD elevate if you prompted them, nor can it tell you any of the user’s other special permissions. CSI_IsSession.vbs, however, relies on whoami (not present on XP and 2003), is only provided in VBS and is a fairly large chunk of code. This code is a very brief, universal way to check for admin rights without attempting to make changes.
UPDATE: 2011-10-29 - Version 1.31 - fixed XP Bug.
UPDATE: 2011-10-26 - Version 1.3 - does not rely on default permissions on <windows>\system32\config which can be easily changed if a protected admin opens the folder and answers "yes" to the prompt "do you want permanent permissions to this folder"
Also VBScript implementation does not depend on CMD.EXE or other executables.
Code ported to PowerShell as well.
Download the attachment for the .CMD/.BAT, .VBS and .PS1 versions of this script code.