$cs.Sys_ExistProcess
Description
Section titled “Description”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.
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