我目前正在使用 vbscript 执行一个批处理文件,以简单地隐藏每次运行批处理时弹出的 cmd 窗口。
我现在要完成的是将参数传递给该批处理文件。vbs 正在运行wscript "c:\batchlauncher.vbs" "c:\batch.bat"
。我想做类似的事情;wscript "c:\batchlauncher.vbs" "c:\batch.bat" ["batch.argument"]
以任何可以完成我需要的顺序或语法。
这就是我所拥有的:
批处理启动器.vbs
'--------------------8<----------------------
sTitle = "Batch launcher"
Set oArgs = WScript.Arguments
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
If oArgs.Count <> 1 Then
' Will die after 10 seconds if no one is pressing the OK button
oShell.Popup "Error: You need to supply a file path " _
& "as input parameter!", 10, sTitle, vbCritical + vbSystemModal
Wscript.Quit 1
End If
sFilePath = oArgs(0)
If Not oFSO.FileExists(sFilePath) Then
' Will die after 10 seconds if no one is pressing the OK button
oShell.Popup "Error: Batch file not found", _
10, sTitle, vbCritical + vbSystemModal
Wscript.Quit 1
End If
' add quotes around the path in case of spaces
iRC = oShell.Run("""" & sFilePath & """", 0, True)
' Return with the same errorlevel as the batch file had
Wscript.Quit iRC
'--------------------8<----------------------