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.
IsProcessRunning
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
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,
Thanks again,
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Hmmm. Not sure, but I wonder if this will give any clues:
http://www.mjtnet.com/forum/viewtopic.php?t=2706
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?