管理员权限 - 翼展电脑服务中心


VBS以管理员身份运行程序

2019-8-4 乱云飞 评论(0) 浏览(703) 标签: VBS 管理员权限

Option Explicit
RunAsAdmin
Msgbox CreateObject("WScript.Shell").CurrentDirectory
' 以管理员身份运行 By Yu2n
Sub RunAsAdmin()
	Dim oItems, vItem, sVer, nVer, vArg, sArgs, sCurDir
	Set oItems = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
	For Each vItem In oItems
		sVer = vItem.Version
	Next
	Set oItems = Nothing
	nVer = Clng(Split(sVer, ".")(0) & Split(sVer, ".")(1))
	If nVer >= 60 Then
		If Not WScript.Arguments.Named.Exists("RunAsAdmin") Then
			For Each vArg In WScript.Arguments
				sArgs = sArgs & " """ & vArg & """"
			Next
			sArgs = sArgs & " /RunAsAdmin:True"
			CreateObject("Shell.Application").ShellExecute "WScript.exe", _
				"""" & WScript.ScriptFullName & """" & sArgs, "", "runas", 1
			WScript.Quit(0)
		Else
			sCurDir = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\") -1)
			CreateObject("WScript.Shell").CurrentDirectory = sCurDir
		End If
	End If
End Sub
预ICP备10086-001号 © 翼展网/80C.CC 技术支持/洛阳翼展科技
TEL / 13213610060 QQ / 345794501
Powered by emlog