返回列表 发帖

[问题求助] vbs使用Shell.ShellExecute如何隐藏执行/运行批处理文件(已解决)

本帖最后由 lomey 于 2016-11-20 00:41 编辑

如何隐藏运行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 COPY

回复 4# pcl_test


    谢谢,已解决

TOP

Shell.ShellExecute(file, [Arguments], [Directory], [Operation], [Show])

TOP

有用的就这俩句
Set sh = CreateObject("Shell.Application")
call sh.ShellExecute( file, args, , "runas" ) COPY

TOP

回复 1# lomey


    你上面写一大串是要干啥?

TOP

返回列表