转载:隐藏bat窗口在后台运行(找了好久)

时间:2023-03-08 19:29:16

https://mp.weixin.qq.com/s?__biz=MzU4MjY1ODA3Nw==&mid=2247484277&idx=1&sn=8b5d98aab3827b78f528fe4b2143d929&chksm=fdb5b207cac23b11fcea56618fe71d6b548264611d054e3c8b19903bafe6580c60ed703c7120&mpshare=1&scene=1&srcid=1203sXJZX3PX5lKijCrYbu4S&pass_ticket=rMlcpEzUGxtN1VC1Xo5MV7wY6Juk2nxik4lWz9VW%2FsDbre6EcK3qw66tI2hPHxPL#rd

现有一个hello.bat(内容为任意,一般希望隐藏bat窗口会较长时间运行的脚本)

@echo off
echo hello
pause

借助VBscript实现隐藏bat窗口,后台运行hello.bat

首先创建一个hiderun.bat

cscript.exe /e:vbscript hide.vbs

其中hiderun.bat调用vbs,hide.vbs内容如下:

CreateObject("WScript.Shell").Run "cmd /cC:\Users\Administrator\Desktop\hello.bat",0

双击运行hiderun.bat即可后台运行hello.bat。其中间经过一个跳板,即hide.vbs。其中调用WshShell.Run的第2个参数0为SW_HIDE(隐藏窗口并激活另一窗口)