Process running condition and workaround script suggestions
I love the new File and Registry Exists/Does Not Exist conditions. If I can make a suggestion, I think a process running/not running condition would be very useful as well as a feature request.
Since we don't have this feature yet, I thought I'd share some scripts I'm using to work around this:
BAT to check for running process - fails (exit code 7) if running, passes if not (exit code 6):
@echo off
SETLOCAL EnableExtensions
set EXE=TeamViewer.exe
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto FOUND
EXIT /B 6
goto FIN
:FOUND
EXIT /B 7
:FIN
Additional mods to step: Must add 6 as a success code. Otherwise, just change line 6 to "EXIT /B 0"
When I'm deploying Java, the above code isn't as useful, since there's a good chance someone will almost always be running either java.exe, iexplore.exe, and/or firefox.exe. So I found the following VBScript to prompt the user to consent to the update before it starts:
Set objShell = CreateObject("Wscript.Shell")
intReturn = objShell.Popup("Do you want to update java? All instances of IE and Firefox will be closed. Please save your work before clicking Yes. To cancel, click No.", 86400, "Update Java", 4 + 32)
If intReturn = 6 Then
Wscript.Quit(6)
ElseIf intReturn = 7 Then
Wscript.Quit(7)
Else
Wscript.Quit(6)
End If
Additional mods to step:
- Has to be an Install step pointed to the vbs file.
- Again, requires success code 6 be added.
- Custom command line has to be changed to cscript.exe //i "PromptToInstallJava.vbs" so that the user can see the prompt.
- Logged on State should be Only run if a user is logged on so you don't unnecessarily delay your deployment.
- Run As should be changed to Logged on User.
- I also set a custom timeout of 2160 minutes for the entire package so the user would have 24 hours to click Yes if they weren't able to run it right away.
Hope this helps someone else that wants to deploy with as little disruption as possible to the users!
Comments
I ran into a similar problem today. I wanted to run the uninstaller for Dymo LabelMaker in one step, and then run the installer for the new version in a later step. My problem was that the uninstaller process returns immediately after spawning a second process to actually do the removal. Here's a short PowerShell step I placed between the two. It waits up to 5 minutes for that spawned process to terminate before moving on to the installation phase. I'll probably reuse it in future packages.