-
August 12th, 2004, 03:30 PM #1
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
-
August 12th, 2004, 03:35 PM #2
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?
-
August 12th, 2004, 04:06 PM #3
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"
-
August 12th, 2004, 04:07 PM #4
Just the local computer. And it can be just a one-time check.
-
August 12th, 2004, 04:08 PM #5
Dang, that was fast. That's pretty much what I needed. Thanks! I will test it out.
-
September 28th, 2004, 05:37 PM #6Junior 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.
-
August 18th, 2009, 11:34 AM #7Junior 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
-
August 18th, 2009, 05:04 PM #8Junior 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
-
August 13th, 2010, 10:59 AM #9Junior 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
-
December 20th, 2012, 04:13 AM #10Junior Member
- Join Date
- Dec 2012
- Posts
- 1
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
vbScript multi-line execution problem
By SWarrior2k in forum Applications and Operating SystemsReplies: 7Last Post: May 14th, 2004, 12:21 PM -
Mozilla stopped working?
By d1sc g0lf3r in forum Linux and UnixReplies: 6Last Post: February 19th, 2004, 03:41 AM -
vbs scripting - option box?
By DVNT1 in forum Webmastering and ProgrammingReplies: 13Last Post: September 11th, 2003, 09:33 PM -
how to stop hot linking in angelfire?
By JacobM5727 in forum Webmastering and ProgrammingReplies: 9Last Post: March 22nd, 2003, 04:26 PM -
script to query a running process
By cornhusker in forum General Tech DiscussionReplies: 0Last Post: November 15th, 2002, 10:22 PM



LinkBack URL
About LinkBacks



Reply With Quote

Hi, Are you ready to start enjoy of your weekend with amazing shows and movies:
My fav shows and movis