Menu
CCMEXEC.COM – Enterprise Mobility
  • Home
  • General
  • Configuration Manager
  • Windows 10
  • Intune
  • GitHub
  • Windows 11
  • About the author
CCMEXEC.COM – Enterprise Mobility

Fail a task sequence or program if a process is running

Posted on August 15, 2011August 15, 2011 by Jörgen Nilsson

When upgrading certain applications for instance plug-ins to Internet Explorer, Internet explorer must not be running if the upgrade is to be successful. I answered this question on the Technet forum during the week and I thought I would share the simple script here.
I have a more advanced script which prompts the user to close open applications with the possibility to postpone the upgrade, I will post that later it just needs a bit more cleaning up 😉

The script can be used as a step in a  Task Sequence or “run this program before” and if you want to check more processes just add a new line as the script uses a command-line argument to pass the process-name to check status.

Example:

checkprocess1

Example syntax: cscript.exe checkprocess.vbs iexplore.exe

Script:

'The script will return error code 1 if process is running
'Processname can be passed on the command line as a variable
'Example cscript.exe checkprocess.vbs Iexplore.exe

Option explicit
DIM strComputer,strProcess
DIM Args

Set args = WScript.Arguments
strProcess = args.Item(0)

If args.count <> "1" then
wscript.echo "incorrect syntax"
wscript.echo "Syntax example = checkprocess.vbs notepad.exe"
end if

IF isProcessRunning(strProcess) THEN
wscript.quit(1)

END IF
FUNCTION isProcessRunning(BYVAL strProcessName)

DIM objWMIService, strWMIQuery

strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"

SET objWMIService = GETOBJECT("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

IF objWMIService.ExecQuery(strWMIQuery).Count > 0 THEN
isProcessRunning = TRUE
ELSE
isProcessRunning = FALSE
END IF

END FUNCTION

5 thoughts on “Fail a task sequence or program if a process is running”

  1. Wojciech says:
    August 15, 2011 at 3:09 pm

    Thanks for this post. I’m waiting for more advanced scripts 🙂

    Reply
  2. A-Bat says:
    August 17, 2011 at 9:59 pm

    Hi Jörgen…

    Is a great blog you have, I would like to consult you about sccm deployment FEP 2010,
    when make the process for deployment of FEP Clients the deployment does not run on computers.

    which Log files can use to identify the problem?

    Thanks for Help…

    Reply
  3. Magnus says:
    September 13, 2011 at 9:30 am

    hi, when will we see the more advanced script ? Today I´m killing Iexplorer before upgrading Activex, but it´s not very nice for users.

    Reply
  4. Jörgen Nilsson says:
    September 13, 2011 at 1:29 pm

    Hi, thanks for the reminder, it is now out there 🙂

    Reply
  5. Jeremy says:
    July 25, 2013 at 11:42 pm

    I have a task sequence setup for uninstalling old versions of Java, and then installing the latest. It works great when IE is closed on the client machines. The information in this article is exactly what I want to do. I want the task sequence to fail if iexplore.exe is running. I tried the above script on a machine. When I open IE on the client receiving the task, it fails and gives me the error code, which is what I expect. However, when I run the task sequence on the same machine with IE closed, I get the same error message. I want the task sequence to continue if IE is closed. Any ideas as to what I might be doing wrong?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

My name is Jörgen Nilsson and I work as a Senior Consultant at Onevinn in Malmö, Sweden. This is my blog where I will share tips and stuff for my own and everyone elses use on Enterprise Mobility and Windows related topics.
All code is provided "AS-IS" with no warranties.

Tweets by ccmexec

Recent Posts

  • Windows Servicing, Personal Teams and Success.cmd
  • Windows MDM Security Baseline – Settings Catalog
  • Configuring MS Edge Security Baseline v107 using Settings Catalog
  • Configuring Desktop App Installer using CSP and script?!
  • Customizing Taskbar and Start in Windows 11 22h2 with PowerShell

©2023 CCMEXEC.COM – Enterprise Mobility | WordPress Theme by Superb Themes
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.Accept Reject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT