Skip to content

$cs.Sys_WaitForProcessToExist

Waits for a process to appear/start, checking every IntervalSec seconds up to a total of MaxWaitSec seconds. If the process already exists, returns immediately. Same caveat as $cs.Sys_WaitForProcess: this always returns silently, with no indication of whether the process actually appeared or the timeout was reached — check $cs.Sys_ExistProcess(...) afterward if you need to know.

$cs.Sys_WaitForProcessToExist(string processname, int MaxWaitSec, int IntervalSec)

Name of the process to wait for.

Maximum total number of seconds to wait for the process to appear.

Number of seconds to sleep between each check.

None.

Wait for a spawned process to actually start before acting on it:

Terminal window
$cs.Job_WriteLog("Waiting up to 30 seconds for clickshare_native.exe to start")
$cs.Sys_WaitForProcessToExist("clickshare_native.exe", 30, 1)
if ($cs.Sys_ExistProcess("clickshare_native.exe"))
{
$cs.Sys_KillProcess("clickshare_native.exe")
}

Launch a setup executable asynchronously, wait for its actual process to appear, then wait for it to finish:

Terminal window
Start-Process -FilePath "$global:Packageroot\setup.exe" -ArgumentList "/silent"
$cs.Job_WriteLog("Waiting up to 20 seconds for setup.exe to start")
$cs.Sys_WaitForProcessToExist("setup.exe", 20, 1)
if ($cs.Sys_ExistProcess("setup.exe"))
{
$cs.Job_WriteLog("setup.exe started, waiting for it to complete")
$cs.Sys_WaitForProcess("setup.exe", 600, 5)
}
else
{
$cs.Job_WriteLog("setup.exe never started within the timeout")
}

$cs.Sys_ExistProcess $cs.Sys_WaitForProcess $cs.Sys_KillProcess