Skip to content

$cs.Sys_ExistProcess

Checks whether a process with the given name is currently running. The file extension is stripped automatically, so "notepad" and "notepad.exe" both work. Note: if an internal error occurs while checking, the function returns true rather than false or throwing — so a “no” result is reliable, but a “yes” should not be treated as an absolute guarantee in every edge case.

$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