可能将这个(来自 VBscript 的 WhoAmI)与这个(UAC Turned On)结合起来。
这是代码,不幸的是,XP 的先决条件是“whoami.exe”,可以在 XP(维基百科)的资源工具包或支持工具中找到——我仍然想找到一种方法来避免它。
If UserPerms("Admin") Then
Message = "Good to go"
Else
Message = "Non-Admin"
End If
If UACTurnedOn = true Then
Message = Message & ", UAC Turned On"
Else
Message = Message & ", UAC Turned Off (Or OS < Vista)"
End If
Wscript.echo Message
Function UserPerms (PermissionQuery)
UserPerms = False ' False unless proven otherwise
Dim CheckFor, CmdToRun
Select Case Ucase(PermissionQuery)
'Setup aliases here
Case "ELEVATED"
CheckFor = "S-1-16-12288"
Case "ADMIN"
CheckFor = "S-1-5-32-544"
Case "ADMINISTRATOR"
CheckFor = "S-1-5-32-544"
Case Else
CheckFor = PermissionQuery
End Select
CmdToRun = "%comspec% /c whoami /all | findstr /I /C:""" & CheckFor & """"
Dim oShell, returnValue
Set oShell = CreateObject("WScript.Shell")
returnValue = oShell.Run(CmdToRun, 0, true)
If returnValue = 0 Then UserPerms = True
End Function
Function UACTurnedOn ()
On Error Resume Next
Set oShell = CreateObject("WScript.Shell")
If oShell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA") = 0 Then
UACTurnedOn = false
Else
UACTurnedOn = true
End If
End Function