バッチファイルで、「管理者として実行」されているか?を判定する。
もし、Vista以降か、.NET Framework が入っていれば、
vbc IsUserAnAdmin.vb
Module Module1
Declare Function IsUserAnAdmin lib "shell32.dll" () As Integer
Public Function Main() As Integer
Return IsUserAnAdmin
End Function
End Module
IsUserAnAdmin.cmd
IsUserAnAdmin.exe
if %errorlevel%==0 echo「管理者として実行」されている
if %errorlevel%==1 echo「管理者として実行」されていない
もし、Windows7以降か、PowerShell 2.0 が入っていれば、
IsUserAnAdmin.ps1
Add-Type -Language VisualBasic @"
Public Class Shell32
Declare Function IsUserAnAdmin Lib "shell32.dll" () As Integer
End Class
"@
Exit [Shell32]::IsUserAnAdmin()
あるいは、バッチファイル内の1行で
PowerShell "Add-Type -Language VisualBasic 'Public Class Shell32:Declare Function IsUserAnAdmin Lib ""shell32.dll"""" () As Integer:End Class';Exit [Shell32]::IsUserAnAdmin();"