To kill a process in a Windows script environment, PowerShell is the perfect tool. Just make a PowerShell script file:
script file: kill_process.ps1
This script kills the process named MyProcess if it exists. The error action prevents the script from outputting information if an error occurs, for example if the process does not exist.
Get-Process -Name "MyProcess" -ErrorAction SilentlyContinue | Stop-Process
To run the script, you must run the MSDos command:
powershell -File "kill_process.ps1"
In case the execution of scripts is disabled in Windows for security reasons, the following command will be used in an MSDos console:
powershell -Command Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Very useful as a pre-build event in Visual Studio when you want to compile a project whose debug leaves a working process in the system, this one preventing the compilation …