Skip to content

$cs.Sys_ExistProcess

Checks whether a process with the given name is currently running, in any session. The file extension is stripped automatically, so "notepad" and "notepad.exe" both work. The name must match the whole process name (not case-sensitive) — unlike $cs.Sys_KillProcess, which matches part of the name. If an error occurs while checking, the function throws an exception.

$cs.Sys_ExistProcess(string processname)

Name of the process to check for. The .exe extension is optional.

Boolean. $true if the process is currently running, otherwise $false.

Check whether the target application is running before killing it and continuing an in-place upgrade:

Terminal window
if ($cs.Sys_ExistProcess("Firefox.exe"))
{
$cs.Job_WriteLog("Firefox is running, killing it before continuing")
$cs.Sys_KillProcess("Firefox")
}

Skip a disruptive upgrade entirely if the application is currently in use, instead of forcing it closed:

Terminal window
if ($cs.Sys_ExistProcess("Outlook"))
{
$cs.Job_WriteLog("Outlook is currently running, postponing upgrade to avoid data loss")
throw "Outlook is running, aborting install"
}
else
{
$cs.Job_WriteLog("Outlook is not running, proceeding with upgrade")
}

Warn before removing an application’s files during uninstall if it still appears to be running:

Terminal window
if ($cs.Sys_ExistProcess("MyLegacyApp"))
{
$cs.Job_WriteLog("MyLegacyApp is still running, files may be locked during removal")
}

$cs.Sys_KillProcess $cs.Sys_WaitForProcess $cs.Sys_WaitForProcessToExist