WshShellオブジェクトの.Runメソッドと.Execメソッドについて読んでください(CreateObject("Wscript.Shell")
)。WshScriptExecbWaitOnReturn
オブジェクトの.Runへのパラメーターと.Status(および.Exitcode)プロパティに注意を払うようにしてください。この回答には、.Runおよび.Execのサンプルコードが含まれています。
アップデート:
a.vbs(本番品質コードではありません!):
Option Explicit
Const WshFinished = 1
Dim goWSH : Set goWSH = CreateObject("WScript.Shell")
Dim sCmd, nRet, oExec
sCmd = "cscript .\b.vbs"
WScript.Echo "will .Run", sCmd
nRet = goWSH.Run(sCmd, , True)
WScript.Echo sCmd, "returned", nRet
sCmd = "cscript .\c.vbs"
WScript.Echo "will .Exec", sCmd
Set oExec = goWSH.Exec(sCmd)
Do Until oExec.Status = WshFinished : WScript.Sleep 100 : Loop
WScript.Echo sCmd, "returned", oExec.ExitCode
WScript.Echo "done with both scripts"
WScript.Quit 0
.b.vbsを実行します:
MsgBox(WScript.ScriptName)
WScript.Quit 22
および.Execsc.vbs:
MsgBox(WScript.ScriptName)
WScript.Quit 33
出力:
cscript a.vbs
will .Run cscript .\b.vbs
cscript .\b.vbs returned 22
will .Exec cscript .\c.vbs
cscript .\c.vbs returned 33
done with both scripts
MsgBoxesは、a.vbsがb.vbsとc.vbsを待機していることを証明します。
アップデートII-VBScriptのマルチプロセッシング((c)@DanielCook):
ax.vbs:
Option Explicit
Const WshFinished = 1
Dim goWSH : Set goWSH = CreateObject("WScript.Shell")
' Each cmd holds the command line and (a slot for) the WshScriptExec
Dim aCmds : aCmds = Array( _
Array("cscript .\bx.vbs", Empty) _
, Array("cscript .\cx.vbs", Empty) _
)
Dim nCmd, aCmd
For nCmd = 0 To UBound(aCmds)
' put the WshScriptExec into the (sub) array
Set aCmds(nCmd)(1) = goWSH.Exec(aCmds(nCmd)(0))
Next
Dim bAgain
Do
WScript.Sleep 100
bAgain = False ' assume done (not again!)
For Each aCmd In aCmds
' running process will Or True into bAgain
bAgain = bAgain Or (aCmd(1).Status <> WshFinished)
Next
Loop While bAgain
For Each aCmd In aCmds
WScript.Echo aCmd(0), "returned", aCmd(1).ExitCode
Next
WScript.Echo "done with both scripts"
WScript.Quit 0
.Execs bx.vbs
Do
If vbYes = MsgBox("Tired of this rigmarole?", vbYesNo, WScript.ScriptName) Then Exit Do
WScript.Sleep 300
Loop
WScript.Quit 22
およびcx.vbs:
Do
If vbYes = MsgBox("Tired of this rigmarole?", vbYesNo, WScript.ScriptName) Then Exit Do
WScript.Sleep 500
Loop
WScript.Quit 33
エラー処理に多大な労力を費やさずに、これを職場で行わないでください。