/build/static/layout/Breadcrumb_cap_w.png

check multiple processes running

I have written a code to check 2 processes, please guide me how can i check, multiple processes by modifying below script? if i check 7-8 processes like below, then that script will be too long, and lengthy.


dim sProcessName, sComputer, oWmi, oShell, colProcessList
sProcessName = "notepad.exe"
sprocessname1 = "iexplore.exe"
sComputer = "." ' use "." for local computer
Set oWmi = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")

Set oShell = CreateObject("WScript.Shell")
Set colProcessList = oWmi.ExecQuery _
("Select * from Win32_Process Where Name = '" & sProcessName & "'")
Set colProcessList1 = oWmi.ExecQuery _
("Select * from Win32_Process Where Name = '" & sProcessName1 & "'")

If colProcessList.Count = 1 Then
Do
msgbox "Adobe Acrobat Application is running Please close it."
Set colProcessList = oWmi.ExecQuery _
("Select * from Win32_Process Where Name = '" & sProcessName & "'")
Loop While colProcessList.Count=1
End if
If colProcessList1.Count = 1 Then
Do
msgbox "Adobe Acrobat Application is running Please close it."

Set colProcessList1 = oWmi.ExecQuery _
("Select * from Win32_Process Where Name = '" & sProcessName1 & "'")
Loop While colProcessList1.Count=1
End if
msgbox "NoThanx sir"

0 Comments   [ + ] Show comments

Answers (1)

Posted by: anonymous_9363 14 years ago
Red Belt
0
- Create a dictionary with the process names as the keys and "friendly" names for the processes as the items. You'll use the friendly name to present a message to the user. Use an array instead of a dictionary if you're more comfortable with that.

- Put the code you have into a function, into which you will pass the dictionary object.

- Add into the function a loop to "walk" through the dictionary, using the dictionary key to get the process name and the item to get the friendly name.

- Check out the DevGuru web site for guidance on using the Dictionary object.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ