VBS以管理员身份运行程序 - 洛阳翼展电脑


VBS以管理员身份运行程序

2019-8-4 乱云飞 标签: 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
本文链接:http://80c.cc/ez/237.html
0

发表评论:

VirtualCamera:在录像机中虚拟一个通道显示电脑桌面、视频文件、USB摄像头~
预ICP备10086-001号 © 翼展网/80C.CC 技术支持/洛阳翼展科技
TEL / 13213610060 QQ / 345794501
Powered by emlog