-
Notifications
You must be signed in to change notification settings - Fork 1
/
terminate-icue.ps1
48 lines (37 loc) · 1.1 KB
/
terminate-icue.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
param(
[switch]$pluginhost
)
$retriesRemaining = 24
$retryInterval = 5
$minRunningTime = 20
$processName = "icue.exe"
$processBaseName = (New-Object System.IO.FileInfo($processName)).BaseName
if ($pluginhost)
{
$processName = "icuedevicepluginhost.exe"
}
function checkIsRunning()
{
$process = Get-Process $processBaseName -ErrorAction SilentlyContinue | Select-Object -First 1
if ($process) {
$delay = 0
$runningTime = (New-TimeSpan -Start $process.StartTime).TotalSeconds
Write-Host "$processName has been running for $runningTime seconds"
if ($runningTime -lt $minRunningTime) {
$delay = $minRunningTime - $runningTime
}
Write-Host "$processName is running, terminating in $delay`s..."
Start-Sleep -s $delay
taskkill /f /t /im $processName
} else {
$retriesRemaining--
if ($retriesRemaining -gt 0) {
Write-Host "$processName not running, retrying in $retryInterval`s. (Retries remaining: $retriesRemaining)"
Start-Sleep -s $retryInterval
checkIsRunning;
} else {
Write-Host "Max retries reached, giving up"
}
}
}
checkIsRunning;