I need some help - I need to run a process kill script in background for an uninstall script. When I start uninstalling, the uninstaller opens processes with error notification (like license Server not fouind, so nothing important) that need to be clicked away with ok or just killed.
The kill script is just a script that checks if a specific process is running and kills it - so it runs in a loop until it gets killed itself.
Now how can i start this kill script while still processing the psadt script.
What you need to do is within your process_kill_script.ps1 is capture the process id of the correct executable that is triggered that you need to kill.
I had a similar dilema when trying to extract an MSI file from within an EXE, which required me to run the EXE (as Admin), which spawned another EXE that extracted the MSI, Once I could retrieve the MSI file, I could kill both of the EXEs.
This is basically what i did:
# Path to Installer
$VPNInstaller = "C:\Temp\myexecutable.exe"
#...
try {
$VPNProc = Start-Process -FilePath $VPNInstaller -PassThru -ErrorAction Stop
Write-Log "Installer started with PID: $($VPNProc.Id)"
} catch {
Write-Log "Failed to start Installer. Error: $_" "ERROR"
exit 1
}
# Wait for VPN Setup process to start
Write-Log "Waiting for VPN setup process to start..."
$VPNSetupProc = $null
$Timeout = 300 # seconds (5-minute timeout)
$Elapsed = 0
$WaitInterval = 10
while (-not $VPNSetupProc -and $Elapsed -lt $Timeout) {
Start-Sleep -Seconds $WaitInterval
$Elapsed += $WaitInterval
$VPNSetupProc = Get-Process | Where-Object { ($_.ProcessName -like "MyClientVPN*") -and ($_.Id -ne $($VPNProc.Id)) }
Write-Log "Checking for VPN setup process... Elapsed time: $Elapsed seconds"
}
if ($VPNSetupProc) {
Write-Log "Detected VPN setup process with PID: $($VPNSetupProc.Id)"
} else {
Write-Log "VPN setup process not found within timeout." "ERROR"
Stop-Process -Id $VPNProc.Id -ErrorAction SilentlyContinue
exit 1
}
# ...
# more code in here
# ...
# Stop VPN Installer & VPN Setup processes
Stop-Process -Id $VPNProc.Id -ErrorAction SilentlyContinue
Write-Log "VPN Installer process (PID: $($VPNProc.Id)) stopped."
if ($VPNSetupProc) {
Stop-Process -Id $VPNSetupProc.Id -ErrorAction SilentlyContinue
Write-Log "VPN Setup process (PID: $($VPNSetupProc.Id)) stopped."
}
I hope this may give you some pointers that may solve your issue