[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] 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# lomey


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

TOP

有用的就这俩句
  1. Set sh = CreateObject("Shell.Application")
  2. call sh.ShellExecute( file, args, , "runas" )
复制代码

TOP

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

TOP

回复 4# pcl_test


    谢谢,已解决

TOP

返回列表