$cs.Sys_WaitForProcess
Description
Section titled “Description”Waits for an already-running process to exit, checking every IntervalSec seconds up to a total of MaxWaitSec seconds. If the process isn’t running to begin with, returns immediately with no error. Important: this function always returns silently, whether the process actually exited or the timeout was simply reached — there is no return value to tell you which happened. If you need to know, check $cs.Sys_ExistProcess(...) again afterward yourself.
Syntax
Section titled “Syntax”$cs.Sys_WaitForProcess(string processname, int MaxWaitSec, int IntervalSec)
Parameters
Section titled “Parameters”processname (String)
Section titled “processname (String)”Name of the process to wait for.
MaxWaitSec (Integer)
Section titled “MaxWaitSec (Integer)”Maximum total number of seconds to wait for the process to exit.
IntervalSec (Integer)
Section titled “IntervalSec (Integer)”Number of seconds to sleep between each check.
Return value
Section titled “Return value”None.
Example
Section titled “Example”Wait for a setup process to finish, then check $cs.Sys_ExistProcess afterward to tell whether it actually exited or the wait simply timed out:
if ($cs.Sys_ExistProcess("setup.exe")){ $cs.Job_WriteLog("Waiting up to 60 seconds for setup.exe to finish") $cs.Sys_WaitForProcess("setup.exe", 60, 1) if ($cs.Sys_ExistProcess("setup.exe")) { $cs.Job_WriteLog("setup.exe is still running after timeout") }}Wait for a slow installer’s background helper process to finish before cleaning up temporary files:
$cs.Job_WriteLog("Waiting up to 300 seconds for the installer helper process to complete")$cs.Sys_WaitForProcess("InstallerHelper", 300, 5)if ($cs.Sys_ExistProcess("InstallerHelper")){ $cs.Job_WriteLog("InstallerHelper did not finish in time, forcing it closed before cleanup") $cs.Sys_KillProcess("InstallerHelper")}Remove-Item -Path "$env:TEMP\InstallerHelper" -Recurse -Force -ErrorAction SilentlyContinueRelated functions
Section titled “Related functions”$cs.Sys_ExistProcess $cs.Sys_WaitForProcessToExist $cs.Sys_KillProcess