+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    RAR
    RAR is offline
    Member RAR's Avatar
    Join Date
    Oct 2001
    Location
    Michigan
    Posts
    408

    Need VB Script to check and see if a process is running.

    I need a simple VB Script that will check if a certain process is running. For instance, if notepad.exe is running it will be in the task manager processes. How can I have a script check to see if it is running?

    RAR

  2. #2
    addicted DVNT1's Avatar
    Join Date
    Oct 2001
    Location
    Ohio
    Posts
    6,103
    Do you need to check all computers in a Domain, a single computer on the network, or just the local computer?

    A one time check or periodically check?

  3. #3
    addicted DVNT1's Avatar
    Join Date
    Oct 2001
    Location
    Ohio
    Posts
    6,103
    for a local computer, here is one way:
    Code:
    set service = GetObject ("winmgmts:")
    
    for each Process in Service.InstancesOf ("Win32_Process")
    	If Process.Name = "notepad.exe" then
    		wscript.echo "Notepad running"
    		wscript.quit
    	End If
    next
    wscript.echo "notepad not running"

  4. #4
    RAR
    RAR is offline
    Member RAR's Avatar
    Join Date
    Oct 2001
    Location
    Michigan
    Posts
    408
    Just the local computer. And it can be just a one-time check.

  5. #5
    RAR
    RAR is offline
    Member RAR's Avatar
    Join Date
    Oct 2001
    Location
    Michigan
    Posts
    408
    Dang, that was fast. That's pretty much what I needed. Thanks! I will test it out.

  6. #6
    Junior Member
    Join Date
    Sep 2004
    Posts
    8
    strComputer = Inputbox("Computer to connect to?")
    'strProcess = Inputbox("Process to Kill?")
    'strComputer = "iscomputer"
    strProcess = "notepad.exe"
    Set wbemLocator = CreateObject("WbemScripting.SWbemLocator")
    Set wbemServices = wbemLocator.ConnectServer(strComputer)
    Set wbemObjectSet = wbemServices.InstancesOf("Win32_Process")
    For Each wbemObject In wbemObjectSet
    If LCase(wbemObject.Name) = strProcess Then
    wscript.echo "notepad is running"
    wscript.quit
    End if
    Next
    wscript.echo "notepad is not running"

    for remote comuter name or fixed name also for promting for process name or fixed name.

  7. #7
    apd
    apd is offline
    Junior Member
    Join Date
    Aug 2009
    Posts
    2

    need assistance checking for processes listed in an ini/txt/csv file

    I need to parse a list of processes in a text file to run the check, and spit out a non zero exit code if any of the processes listed in the text file are running. Can be a csv file too, though am assuming a .ini with a process listed on each line would be easiest. Any help is greatly appreciated! I have zero VB scripting experience, but the boss doesn't care about that!

    I've got this script that checks for a hard coded process, assuming I can build off this...


    ' List the processes Running on a Computer



    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colProcesses = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Process WHERE Name = " & _
    "'notepad.exe'")

    If colProcesses.Count = 0 Then
    Wscript.Echo "No scripts are running."
    Else
    For Each objProcess in colProcesses
    Wscript.Echo objProcess.CommandLine
    Next
    End If

  8. #8
    apd
    apd is offline
    Junior Member
    Join Date
    Aug 2009
    Posts
    2
    So I've gotten this far, still having an issue with line 68. Any thoughts?!?

    (68, 5) SWbemObjectSet: Invalid query

    I've verified that it is parsing the lines from a file into an array, its just around the WMI query and the count statement. Any help would be greatly appreciated! Thanks!


    '*************************
    '** Error Checking Routine
    '*************************
    Sub ThrowError (Number, Description)
    ObjApp = ""
    WScript.Echo WScript.ScriptName + " " + CStr(number) + " " + description
    NwmScript.Log WScript.ScriptName + " " + CStr(number) + " " + description
    WScript.Quit number
    End Sub

    Sub EchoAndLog ( message )
    WScript.Echo message
    NwmScript.Log WScript.ScriptName + " - " + message
    End Sub

    ' Parse processes list into array

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("c:\temp\processes.csv", ForReading)

    Const ForReading = 1

    Dim arrFileLines()
    i = 0
    Do Until objFile.AtEndOfStream
    Redim Preserve arrFileLines(i)
    arrFileLines(i) = objFile.ReadLine
    i = i + 1
    Loop
    objFile.Close


    ' List the processes Running on a Computer
    For Each strLine in arrFileLines

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colProcesses = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Process WHERE Name =" & strLine &"")
    If colProcesses.Count=0 Then
    Wscript.Echo "No scripts are running."
    End If

    Next

  9. #9
    Junior Member
    Join Date
    Aug 2010
    Posts
    1
    I want to check and see if a process is running in a domain PC.

    Any idea?

    Thank you

  10. #10
    Junior Member
    Join Date
    Dec 2012
    Posts
    1
    Quote Originally Posted by DVNT1 View Post
    for a local computer, here is one way:
    Code:
    set service = GetObject ("winmgmts:")
    
    for each Process in Service.InstancesOf ("Win32_Process")
    	If Process.Name = "notepad.exe" then
    		wscript.echo "Notepad running"
    		wscript.quit
    	End If
    next
    wscript.echo "notepad not running"
    This script does a one time check, what must be added to this script so that it keeps checking 24x7 and echoes every time it sees this process running?

Quick Reply Quick Reply

If you are already a member, please login above.

What is 10 and 5 added together?

Thread Information

Users Browsing this Thread

There are currently 3 users browsing this thread. (0 members and 3 guests)

Similar Threads

  1. vbScript multi-line execution problem
    By SWarrior2k in forum Applications and Operating Systems
    Replies: 7
    Last Post: May 14th, 2004, 12:21 PM
  2. Mozilla stopped working?
    By d1sc g0lf3r in forum Linux and Unix
    Replies: 6
    Last Post: February 19th, 2004, 03:41 AM
  3. vbs scripting - option box?
    By DVNT1 in forum Webmastering and Programming
    Replies: 13
    Last Post: September 11th, 2003, 09:33 PM
  4. how to stop hot linking in angelfire?
    By JacobM5727 in forum Webmastering and Programming
    Replies: 9
    Last Post: March 22nd, 2003, 04:26 PM
  5. script to query a running process
    By cornhusker in forum General Tech Discussion
    Replies: 0
    Last Post: November 15th, 2002, 10:22 PM

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright 2014 All Enthusiast, Inc