用 WshScriptExec 對(duì)象啟動(dòng)的過程的 ID (PID)。
Object.ProcessID
可以使用 ProcessID 屬性來激活應(yīng)用程序(作為 AppActivate 方法的參數(shù))。
下面的代碼使用 ProcessID 屬性來激活計(jì)算器和筆記本應(yīng)用程序。
Sub delayedSendKeys(str) WScript.Sleep 100 WshShell.SendKeys str End Sub Dim WshShell, oCalc, oNotepad Set WshShell = CreateObject("WScript.Shell") Set oCalc = WshShell.Exec("calc") Set oNotepad = WshShell.Exec("notepad") WScript.Sleep 500 WshShell.AppActivate oCalc.ProcessID
delayedSendKeys "1{+}1~" delayedSendKeys "^C" delayedSendKeys "%{F4}" WshShell.AppActivate oNotepad.ProcessID
delayedSendKeys "1 {+} 1 = ^V"
function delayedSendKeys(str) { WScript.Sleep(100); WshShell.SendKeys(str); } var WshShell = new ActiveXObject("WScript.Shell"); var oCalc = WshShell.Exec("calc"); var oNotepad = WshShell.Exec("notepad"); WScript.Sleep(500); WshShell.AppActivate(oCalc.ProcessID
); delayedSendKeys("1{+}1~"); delayedSendKeys("^C"); delayedSendKeys("%{F4}"); WshShell.AppActivate(oNotepad.ProcessID
); delayedSendKeys("1 {+} 1 = ^V");