在不显示命令行的情况下执行批处理文件 [英] Execute Batch File without Command line visible
问题描述
我必须在不显示命令行的情况下运行批处理文件,但命令行仍会继续弹出.这是我的代码:
I have to run a batch file without showing the command line but the Command line keeps on popping up. This is my code:
@echo off
:SAMPLE
cd /d C:
md %RANDOM%
cd /d D:
md %RANDOM%
cd /d E:
md %RANDOM%
goto SAMPLE
推荐答案
解决方案1 :
将代码保存在批处理文件中,让我们说My.bat
Save your code in a batch file lets say My.bat
创建一个VBScript文件,让它说Master.vbs
并在其中调用您的My.bat
文件.
Create a VBScript file lets say Master.vbs
and call your My.bat
file within it.
让我们假设您的批处理文件位于C:\Test\My.bat
,然后:
Lets assume your batch file is at C:\Test\My.bat
then:
Master.vbs:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Test\My.bat" & Chr(34), 0
Set WshShell = Nothing
它将以不可见/隐藏模式运行您的批处理文件.
It'll run your batch file in invisible/hidden mode.
解决方案2 :
如果可能的话,请使用start
命令修改批处理文件以运行任何程序.默认情况下,start
立即返回,而无需等待程序退出,因此批处理文件将继续运行,并且可能立即退出.再加上修改快捷方式以最小化运行批处理文件,您将只会看到任务栏闪烁,甚至看不到屏幕上的窗口.
If at all possible, modify the batch file to run whatever program with the start
command. By default, start
returns immediately without waiting for the program to exit, so the batch file will continue to run and, presumably, exit immediately. Couple that with modifying your shortcut to run the batch file minimized, and you’ll only see the taskbar flash without even seeing a window onscreen.
这篇关于在不显示命令行的情况下执行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!