标题: [问题求助] vbs使用Shell.ShellExecute如何隐藏执行/运行批处理文件(已解决) [打印本页]
作者: lomey 时间: 2016-11-19 18:55 标题: 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
复制代码
作者: 老刘1号 时间: 2016-11-19 19:00
回复 1# lomey
你上面写一大串是要干啥?
作者: 老刘1号 时间: 2016-11-19 19:01
有用的就这俩句- Set sh = CreateObject("Shell.Application")
- call sh.ShellExecute( file, args, , "runas" )
复制代码
作者: pcl_test 时间: 2016-11-19 19:14
Shell.ShellExecute(file, [Arguments], [Directory], [Operation], [Show])
作者: lomey 时间: 2016-11-20 00:40
回复 4# pcl_test
谢谢,已解决
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |