This quick VBS script tests whether it is running with local administrative rights by trying to write a registry key.
' ------------------------------------------------------------------
' HARRY VERGE - JUL 2006
'
' Quick & Dirty test to see if current user is local admin on PC
' ------------------------------------------------------------------
Option Explicit
CONST HKCUPOL = "HKCU\Software\Policies"
CONST TITLE = "Quick Local Admin Test"
CONST WRITETO = "Attempted write to Registry Key "
Dim objShell
Set objShell = CreateObject("WScript.Shell")
On Error Resume Next
objShell.RegWrite HKCUPOL & "\LocalAdminTest",Now(),"REG_SZ"
If Err.Number = 0 Then
MsgBox WRITETO & HKCUPOL & " succeeded. " & vbcrlf
& vbcrlf & _
"Assuming user has Local Administrator
Permissions.",vbInformation,TITLE
objShell.RegDelete HKCUPOL & "\LocalAdminTest"
Else
MsgBox WRITETO & HKCUPOL & " failed. " & vbcrlf &
vbcrlf &_
"Assuming user does NOT have Local Administrator Permissions, or"
& vbcrlf & _
"if running Vista, this needs to be tested using elevated
privileges." & vbcrlf & vbcrlf & _
"To run in Vista, open a command prompt as administrator, and"
& vbcrlf & _
"then run it again from there.",vbCritical,TITLE
End If
