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

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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.
Answered 07/01/2009 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity