IsProcessRunning

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Mbrower
Newbie
Posts: 8
Joined: Mon Dec 18, 2006 7:35 pm

IsProcessRunning

Post by Mbrower » Mon Apr 30, 2007 4:08 pm

I have a script that uses IsProcessRunning to determine if IE is open. I also use IsProcessRunning to check to see if MS Word is open. It works very well except on a Terminal Server. The IsProcessRunning routine indentifies IE and Word running in other sessions. Is there a way to isolate IsProcessRunning to a single session?

Thank you for any help offered. This forum has been a great resource.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Apr 30, 2007 4:18 pm

Here you go:

Code: Select all

VBSTART
'returns the number of copies of ProcessName that are running for user UserName
'will return 0 if ProcessName is not running
Function IsProcessRunning(ProcessName,UserName)
	Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
	Set colProcessList = oWMIService.ExecQuery ("Select Name from Win32_Process where Name='" & ProcessName & "'")
	IsProcessRunning = 0

	for Each objProcess in colProcessList
		objProcess.GetOwner strUserName, strUserDomain
		if strUserName = UserName then
		   IsProcessRunning = IsProcessRunning + 1
		end if
	next

End Function
VBEND
VBEval>IsProcessRunning("firefox.exe","Marcus"),res
MessageModal>res
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Mbrower
Newbie
Posts: 8
Joined: Mon Dec 18, 2006 7:35 pm

Post by Mbrower » Mon Apr 30, 2007 4:40 pm

Wow, barely got it posted and here is the answer. This forum is amazing!

Mbrower
Newbie
Posts: 8
Joined: Mon Dec 18, 2006 7:35 pm

Post by Mbrower » Mon Apr 30, 2007 11:12 pm

The solution worked perfectly. I added the code, tested it and then found out that the client is logging on to terminal services with the same username from several different computers. I looked in the VBScript reference but was unable to find the correct code to find a session_id or client name(name of computer connecting). I will continue to research, thought maybe this has been done before.

Thanks again,

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue May 01, 2007 7:29 am

Hmmm. Not sure, but I wonder if this will give any clues:
http://www.mjtnet.com/forum/viewtopic.php?t=2706
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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