Windows Script Host  

ProcessID Property

The process ID (PID) for a process started with the WshScriptExec object.

Object.ProcessID

Parameters

Object
WshScriptExec object.

Remarks

You can use the ProcessID property to activate an application (as an argument to the AppActivate method).

Example

The following code uses the ProcessID property to activate the calculator and notepad applications.

[VBScript]
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"
[JScript]
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");

See Also

WshScriptExec Object | AppActivate Method