以静默方式运行一个cmd或BAT [英] Running a CMD or BAT in silent mode
问题描述
我怎样才能以静默方式运行一个cmd或.bat文件?我期待prevent的CMD界面被显示给用户。
How can I run a CMD or .bat file in silent mode? I'm looking to prevent the CMD interface from being shown to the user.
推荐答案
我的StackOverflow问题,提出了一种在运行批处理文件背景(没有DOS窗口中显示)
I have proposed in StackOverflow question a way to run a batch file in the background (no DOS windows displayed)
这应该回答你的问题。
下面是:
这是你的第一个剧本,叫你的第二个脚本与以下行:
From your first script, call your second script with the following line:
wscript.exe invis.vbs run.bat %*
其实,您调用一个vbs脚本:
Actually, you are calling a vbs script with:
- 的[路径] \\你的脚本的名称
- 所有其他由脚本需要的参数(
%*
)
- the [path]\name of your script
- all the other arguments needed by your script (
%*
)
然后,invis.vbs会打电话给你的脚本与 Windows脚本宿主运行( )方法,这需要:
Then, invis.vbs will call your script with the Windows Script Host Run() method, which takes:
- intWindowStyle:0表示无形窗口
- bWaitOnReturn:false意味着您的第一个脚本不需要等待你的第二个脚本来完成
请参阅问题为全面invis.vbs脚本:
See the question for the full invis.vbs script:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False
^^^^^
means "invisible window" ---|
Tammen的反馈后更新:
Update after Tammen's feedback:
如果您是在DOS会话,并要在后台推出另一个脚本,一个简单的 / B
(详见中的same上述问题)可能是不够的:
If you are in a DOS session and you want to launch another script "in the background", a simple /b
(as detailed in the same aforementioned question) can be enough:
您可以使用 启动/ B second.bat
以异步方式从你第一次启动了第二批文件共享您的第一个窗口。
You can use
start /b second.bat
to launch a second batch file asynchronously from your first that shares your first one's window.
这篇关于以静默方式运行一个cmd或BAT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!