$cs.Sys_ExistProcess
Description
Section titled “Description”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.
Syntax
Section titled “Syntax”$cs.Sys_ExistProcess(string processname)
Parameters
Section titled “Parameters”processname (String)
Section titled “processname (String)”Name of the process to check for. The .exe extension is optional.
Return value
Section titled “Return value”Boolean. $true if the process is currently running, otherwise $false.
Example
Section titled “Example”Check whether the target application is running before killing it and continuing an in-place upgrade:
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:
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:
if ($cs.Sys_ExistProcess("MyLegacyApp")){ $cs.Job_WriteLog("MyLegacyApp is still running, files may be locked during removal")}Related functions
Section titled “Related functions”$cs.Sys_KillProcess $cs.Sys_WaitForProcess $cs.Sys_WaitForProcessToExist