Multiple Instances of Process

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Multiple Instances of Process

Post by armsys » Tue Sep 29, 2015 9:30 am

How to detect multiple instances of, say, msched.exe?

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Multiple Instances of Process

Post by JRL » Tue Sep 29, 2015 12:48 pm


armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Multiple Instances of Process

Post by armsys » Tue Sep 29, 2015 10:28 pm

Thanks for referring to the VBS code written by Marcus more than 10 years ago.
Thanks JBL.

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Multiple Instances of Process

Post by JRL » Wed Sep 30, 2015 12:37 pm

armsys wrote:...the VBS code written by Marcus more than 10 years ago.
It is a handy piece of code. I have 25 different scripts using it the last one was written only a month ago.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Multiple Instances of Process

Post by armsys » Sat Oct 03, 2015 9:52 pm

JRL wrote:It is a handy piece of code. I have 25 different scripts using it the last one was written only a month ago.
It's definitely useful.
Recently, for some odd reason, when starting Windows, Macro Scheduler won't run, even though its link is listed in the StartUp folder--C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\Macro Scheduler.lnk.
A moment ago, I wrote the following script (located at %appdata%\Microsoft\Windows\Start Menu\Programs\Startup) to start Macro Scheduler as an automatic backup.
Thank you, Marcus & JRL.

Code: Select all

VBSTART
'returns the number of copies of ProcessName that are running
'will return 0 if ProcessName is not running
Function IsProcessRunning(ProcessName)
   Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
   Set colProcessList = oWMIService.ExecQuery ("Select Name from Win32_Process where Name='" & ProcessName & "'")
   IsProcessRunning = colProcessList.count
End Function
VBEND
// Find out the number (Num) of instances of Macro Scheduler
VBEval>IsProcessRunning("msched.exe"),Num

If>Num=1
  Run>C:\Program Files (x86)\Macro Scheduler 14\msched.exe
Endif

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Multiple Instances of Process

Post by armsys » Sat Oct 03, 2015 9:57 pm

How can we find out Marcus' other useful VBS snippets? :D

User avatar
Meryl
Staff
Posts: 124
Joined: Wed Sep 19, 2012 1:53 pm
Location: Texas
Contact:

Re: Multiple Instances of Process

Post by Meryl » Mon Oct 05, 2015 4:24 pm

Should be able to search forums to find more snippets.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Multiple Instances of Process

Post by armsys » Tue Oct 06, 2015 7:03 am

Meryl wrote:Should be able to search forums to find more snippets.
Of course, I did. The keyword is VBSTART. You'll find plenty of useful VBS snippets. Thanks for your feedback.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts