Skip to content

$cs.Sys_KillProcess

Kills every running process whose name contains processname as a substring (case-insensitive), not just an exact match — for example "chrome" would also match and kill a process named "chromehelper". Pick a name specific enough to avoid collateral kills. Each matching process is killed together with its child processes, and the function waits for each killed process to fully exit before returning. If a process can’t be killed (for example, because access is denied), the function throws an exception.

$cs.Sys_KillProcess(string processname)

Name (or substring of the name) of the process(es) to kill. The .exe extension is optional.

None.

Force-close an application before an in-place upgrade so its files aren’t locked:

Terminal window
if ($cs.Sys_ExistProcess("Firefox.exe"))
{
$cs.Job_WriteLog("Killing Firefox before continuing install")
$cs.Sys_KillProcess("Firefox")
}

Kill a specific helper process by its full name rather than a short substring, to avoid accidentally matching unrelated processes (for example "note" would also match OneNote or notepad++):

Terminal window
$cs.Job_WriteLog("Stopping the vendor update helper before uninstalling the application")
$cs.Sys_KillProcess("VendorUpdateHelper.exe")

Clean up a known set of leftover processes during uninstall:

Terminal window
foreach ($processName in @("AppMain", "AppTray", "AppUpdater"))
{
if ($cs.Sys_ExistProcess($processName))
{
$cs.Job_WriteLog("Killing leftover process $processName")
$cs.Sys_KillProcess($processName)
}
}

$cs.Sys_ExistProcess $cs.Sys_WaitForProcess $cs.Sys_WaitForProcessToExist