需要vbs执行一些命令,比如 ""uwfmgr filter enable"" (统一写入筛选器), 但是这个uwfmgr.exe需要管理员权限才能运行相关命令
目前我是这么写的

Set sst = CreateObject("Shell.Application")
Call sst.ShellExecute("uwfmgr","filter enable", ,"runas",0)

这样可以以管理员身份运行命令, 但是我怎么才能判断uwfmgr执行是成功还是失败的? (管理员cmd运行命令会有返回值)

原来我执行一些cmd命令都是用

intReturn = WScript.CreateObject("wscript.shell").Run("xxxxxx",1,true)

通过判断intReturn是否为0来判断命令执行成功失败, 但是这个不能执行需要管理员权限的命令, 有没有办法让Run能以管理员运行命令?

如何隐藏运行Setup.bat文件

'以管理员身份运行程序的命令admin.vbs 
Set objWMIServices = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 
Set objWbemObjectSet = objWMIServices.ExecQuery(_ 
"SELECT * FROM Win32_Process WHERE " &_ 
"ExecutablePath='" & Replace(WScript.FullName,"\","\\") & "' and " & _ 
"CommandLine LIKE '%" & WScript.ScriptName & "%'") 
for each objWbemObject in objWbemObjectSet 
cmdline = objWbemObject.CommandLine 
next 
if WScript.Arguments.Count then 
file = WScript.Arguments(0) 
if file="/?" then 
call ShowHelp() 
WScript.Quit 
end if 
Set RegEx = new RegExp 
RegEx.IgnoreCase = true 
RegEx.Global = true 
RegEx.Pattern = "\\|\/|\||\(|\)|\[|\]|\{|\}|\^|\$|\.|\*|\?|\+"
temp1 = RegEx.Replace(WScript.ScriptName, "\$&") 
temp2 = RegEx.Replace(file, "\$&") 
RegEx.Global = false 
RegEx.Pattern = "^.*?" & temp1 & "[""\s]*" & temp2 & """?\s*"
args = RegEx.Replace(cmdline, "") 
'WScript.Echo file, args 
else 
file = "Setup.bat"
'args = "/k cd /d """ & CreateObject("WScript.Shell").CurrentDirectory & Chr(34) 
end if 
'核心代码 
Set sh = CreateObject("Shell.Application") 
call sh.ShellExecute( file, args, , "runas" ) 
function ShowHelp() 
dim HelpStr 
HelpStr = "以管理员身份运行程序。" & vbCrLf _ 
& vbCrLf _ 
& WScript.ScriptName & " [program] [parameters]..." & vbCrLf _ 
& vbCrLf _ 
& "program 要运行的程序" & vbCrLf _ 
& "parameters 传递给 program 的参数" & vbCrLf _ 
& vbCrLf 
WScript.Echo HelpStr 
end function

爱逃课的灭火器
1 声望1 粉丝

引用和评论

0 条评论