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"
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)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
- 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.
- 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.
so that the conversation will remain readable.