Check for running processes before deploying

Answered

Comments

7 comments

  • Bart Laureys

    To check if a process is running I use this code, in this case when javaw.exe is running the deployement stops

    %WINDIR%\System32\tasklist /FI "IMAGENAME eq javaw.exe" | find /I /N "javaw.exe"

    also change the Succes codes field to "1"

    enter image description here

    0
    Comment actions Permalink
  • Frederik Huppert

    Works great 😄 thank you !

    0
    Comment actions Permalink
  • Chris James

    Oh nice! I've been using PowerShell myself:

    $Processes = Get-Process
    if ( $Processes.ProcessName -contains "chrome" ) {
        Write-Output "Process Found - stopping"
        Exit 22
    } Else {
        Write-Output "Process Not Found"
        Exit 11
    }
    

    Stop Process if Found

    1
    Comment actions Permalink
  • Frederik Huppert

    Looks interessting too, i will try this method too, since i am personal a fan of powershell.

    0
    Comment actions Permalink
  • Frederik Huppert

    You ever tried to generealize this? I am currently trying to put this script in a package, instead copy and past this script and creating several different versions of it. One script with the process name as a variable, no problem, but how to set something like a package wide variable or passing variables to packages. I am currently using nexted packages to update our RDS Servers. Step1 change user state, Step 2 install/update .... It would be cool to put this like a preflightcheck in front of all other steps but without creating this script for every single nested package.

    0
    Comment actions Permalink
  • kelemvor

    Does this work? I tried something similar to detect it a specific service exists but can't get it to work. I'm using: if (get-service "Tenable Nessus Agent" -ErrorAction SilentlyContinue) { exit 33 } else { exit 44 }

    I have 33 in the Success Codes box and I have the task set to "Stop deployment with Success". Problem is if I type gibberish in the Service name, it still stops and says success.

    If I replace the Exit parts with writing Yes or No to the screen, that seems to work fine. I'm brand new to the PDQ software so I might be doing something wrong. I simply want a way that I can check for a specific file or service before deploying something to check and see if it already exists or not.

    0
    Comment actions Permalink
  • Chris James

    Hey there, my example should work you just need to use Get-Service, and use the DisplayName for the property in the If statement.

    However, in your example, I believe you may have the logic of stop with success backwards. You've told the package that, a code 33 is successful, and to continue onward with the package steps. Which means if the step returns anything other than 0 or 33, to stop the package and mark it as successful.

    When you type in the gibberish service you are probably receiving 44 as a return which is not considered a success code, so the step "fails with success" then stops the package and reports a successful deployment.

    When using Stop deployment with Success, you want the package to stop on that step if a condition in your script is met and you exit with the "fail with success" code you define (22 in my example) and if the condition is not met, to continue onward with the with your defined success code.

    0
    Comment actions Permalink

Please sign in to leave a comment.