欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vbs ShellExecute運行外部程序時如何判斷外部程序執(zhí)行成功與否

 更新時間:2023年06月11日 16:27:22   投稿:mdxy-dxy  
這篇文章主要介紹了vbs ShellExecute運行外部程序時如何判斷外部程序執(zhí)行成功與否,需要的朋友可以參考下

需要vbs執(zhí)行一些命令,比如 ""uwfmgr filter enable"" (統(tǒng)一寫入篩選器), 但是這個uwfmgr.exe需要管理員權(quán)限才能運行相關(guān)命令
目前我是這么寫的

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

這樣可以以管理員身份運行命令, 但是我怎么才能判斷uwfmgr執(zhí)行是成功還是失敗的? (管理員cmd運行命令會有返回值)

原來我執(zhí)行一些cmd命令都是用

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

通過判斷intReturn是否為0來判斷命令執(zhí)行成功失敗, 但是這個不能執(zhí)行需要管理員權(quán)限的命令, 有沒有辦法讓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 的參數(shù)" & vbCrLf _ 
& vbCrLf 
WScript.Echo HelpStr 
end function 

到此這篇關(guān)于vbs ShellExecute運行外部程序時如何判斷外部程序執(zhí)行成功與否的文章就介紹到這了,更多相關(guān)vbs ShellExecute運行外部程序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論