[英]How to execute batch file silently in windows background
i have a batch file which helps to start my rails server.when i am starting my batch file the command prompt is opening but here i need the cmd should not visible to user or it will execute at windows background.I am explaining mt .bat
file code below. 我有一个有助于启动我的Rails Server的批处理文件。当我启动我的批处理文件时,命令提示符正在打开,但是在这里我需要cmd对用户不可见,否则它将在Windows background中执行。我在解释mt
.bat
文件代码如下。
c:
cd c:\\Site\swargadwara_puri
rails server
Please help me. 请帮我。
You could run it silently using a Vbscript file instead. 您可以改为使用Vbscript文件以静默方式运行它。 The Run Method allows you running a script in invisible mode.
运行方法允许您以不可见模式运行脚本。 Create a .vbs file like this one :
创建一个像这样的.vbs文件:
Option Explicit
Dim MyBatchFile
MyBatchFile = "C:\New Floder\toto 1.bat"
Call Run(MyBatchFile,1,False) 'Showing the console
Call Run(MyBatchFile,0,False) 'Hidding the console
'*********************************************************************************
Function Run(MyBatchFile,Console,bWaitOnReturn)
Dim ws,Result
Set ws = CreateObject("wscript.Shell")
'A value of 0 to hide the MS-DOS console
If Console = 0 Then
Result = ws.run(DblQuote(MyBatchFile),Console,bWaitOnReturn)
If Result = 0 Then
'MsgBox "Success"
Else
MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
End If
End If
'A value of 1 to show the MS-DOS console
If Console = 1 Then
Result = ws.run(DblQuote(MyBatchFile),Console,bWaitOnReturn)
If Result = 0 Then
'MsgBox "Success"
Else
MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
End If
End If
Run = Result
End Function
'*********************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'*********************************************************************************
The second argument in this example sets the window style. 本示例中的第二个参数设置窗口样式。 0 means "hide the window, and 1 means "show the window"
0表示“隐藏窗口,1表示“显示窗口”
Complete syntax of the Run method : Run方法的完整语法:
object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
Arguments: 参数:
您可以最小化批处理命令,例如使用:
START /MIN rails server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.