在静默模式下运行CMD或BAT [英] Running a CMD or BAT in silent mode

查看:1857
本文介绍了在静默模式下运行CMD或BAT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以静音模式运行CMD或.bat文件?我希望防止向用户显示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:


  • 脚本的[path] \\\
    ame

  • 脚本需要的所有其他参数c $ c>%* )

  • the [path]\name of your script
  • all the other arguments needed by your script (%*)

然后,invis.vbs将使用 Windows Script Host Run()方法,它需要:

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 同样的上述问题)可以是足够的:

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:


您可以使用 start / 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆