Board logo

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

作者: lomey    时间: 2016-11-19 18:55     标题: vbs使用Shell.ShellExecute如何隐藏执行/运行批处理文件(已解决)

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

如何隐藏运行Setup.bat文件
  1. '以管理员身份运行程序的命令admin.vbs
  2. Set objWMIServices = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
  3. Set objWbemObjectSet = objWMIServices.ExecQuery(_
  4. "SELECT * FROM Win32_Process WHERE " &_
  5. "ExecutablePath='" & Replace(WScript.FullName,"\","\\") & "' and " & _
  6. "CommandLine LIKE '%" & WScript.ScriptName & "%'")
  7. for each objWbemObject in objWbemObjectSet
  8. cmdline = objWbemObject.CommandLine
  9. next
  10. if WScript.Arguments.Count then
  11. file = WScript.Arguments(0)
  12. if file="/?" then
  13. call ShowHelp()
  14. WScript.Quit
  15. end if
  16. Set RegEx = new RegExp
  17. RegEx.IgnoreCase = true
  18. RegEx.Global = true
  19. RegEx.Pattern = "\\|\/|\||\(|\)|\[|\]|\{|\}|\^|\$|\.|\*|\?|\+"
  20. temp1 = RegEx.Replace(WScript.ScriptName, "\$&")
  21. temp2 = RegEx.Replace(file, "\$&")
  22. RegEx.Global = false
  23. RegEx.Pattern = "^.*?" & temp1 & "[""\s]*" & temp2 & """?\s*"
  24. args = RegEx.Replace(cmdline, "")
  25. 'WScript.Echo file, args
  26. else
  27. file = "Setup.bat"
  28. 'args = "/k cd /d """ & CreateObject("WScript.Shell").CurrentDirectory & Chr(34)
  29. end if
  30. '核心代码
  31. Set sh = CreateObject("Shell.Application")
  32. call sh.ShellExecute( file, args, , "runas" )
  33. function ShowHelp()
  34. dim HelpStr
  35. HelpStr = "以管理员身份运行程序。" & vbCrLf _
  36. & vbCrLf _
  37. & WScript.ScriptName & " [program] [parameters]..." & vbCrLf _
  38. & vbCrLf _
  39. & "program 要运行的程序" & vbCrLf _
  40. & "parameters 传递给 program 的参数" & vbCrLf _
  41. & vbCrLf
  42. WScript.Echo HelpStr
  43. end function
复制代码

作者: 老刘1号    时间: 2016-11-19 19:00

回复 1# lomey


    你上面写一大串是要干啥?
作者: 老刘1号    时间: 2016-11-19 19:01

有用的就这俩句
  1. Set sh = CreateObject("Shell.Application")
  2. 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://www.bathome.net/) Powered by Discuz! 7.2