Script to check/kill process before install
The following batch file can be used as an example of how to do a software installation/upgrade when process X is not running. Note that also requires using PsKill from SysInternals. The script will:
- Check for the existence of a running process (.exe) of the software
- Stop the process if detected as running
- Perform a software installation
- Then start the software again
@echo off Set CURPATH = %~dp0 tasklist | findstr /i screenagent.exe echo errorlevel = %ERRORLEVEL% if ERRORLEVEL 0 goto Running if ERRORLEVEL 1 goto DoInstall :exit exit 0 :DoInstall echo Installing NICE ScreenAgent Software... start /wait /i "NICE Agent" "%CURPATH%Setup.exe" start ScreenAgent.exe goto exit :Running echo ScreenAgent Running: stopping execution "%CURPATH%pskill.exe" /accepteula ScreenAgent.exe goto DoInstall
April 9, 2014 at 9:53 am
Thanks for posting this. Just a heads up, I was testing this and was getting an error when pskill.exe was being called – ” ‘”pskill.exe”‘ is not recognized as an internal or external command, operable program or batch file “. The solution was to remove the spaces from “Set CURPATH = %~dp0” (so it was executed as “Set CURPATH=%~dp0”.
April 9, 2014 at 12:41 pm
It was pointed out to me that I should have used the built-in process of taskkill … and not pskill. Old habits die hard. Anyhow if you use taskill instead then it should work (remember to also remove the CURPATH variable)