可以執行使用WshShell.Run
方法DOS命令:
var oShell = WScript.CreateObject("WScript.Shell");
oShell.Run("timeout /t 10", 1 /* SW_SHOWNORMAL */, true /* bWaitOnReturn */);
如果你特別需要,直到按下某個鍵或超時經過暫停腳本執行,你可以完成這使用WshShell.Popup
方法(帶有超時選項的對話框):
var oShell = WScript.CreateObject("WScript.Shell");
oShell.Popup("Click OK to continue.", 10);
但是,此方法也會在cscript下運行時顯示消息框。
本文描述了另一種可能的方法:How Can I Pause a Script and Then Resume It When a User Presses a Key on the Keyboard?簡而言之,您可以使用WScript.StdIn
屬性直接從輸入流中讀取,並以此方式等待輸入。但是,從輸入流讀取不支持超時,並且僅在按下按鍵(而不是任何按鍵)時才返回。無論如何,這是一個例子,以防萬一:
WScript.Echo("Press the ENTER key to continue...");
while (! WScript.StdIn.AtEndOfLine) {
WScript.StdIn.Read(1);
}
工作! thanx – detj 2009-09-18 07:10:11