Discussion:
Win32_PROCESS Class question
(too old to reply)
ddebacker
2005-04-28 09:19:26 UTC
Permalink
Hello,

I'm trying to figure out how to check for the existence of a running
process using WMI inside a VBS file.

The problem I do have is that the process list I get from the WMI
class only contains the processes running under the user context that
launches the script (and the process I'm looking for is running in
another user context).

Is that an expected behaviour? If not, what should I do (I can't run
the VBS under the context that runs the process I'm looking for).

Can anyone help?

What I would like is to have the same kind of behaviour as the
TASKLIST.EXE (that lists ALL the processes running on the machine and
not only the ones running under the specific user context)

Here is how I do it (extract of the codes, some variables declaration
might be missing):

bProcessFound = TRUE
bFoundOnce = FALSE
strLastSeen = NEVER
strProcessName = strProcessString
iTimesFound = 0

Set oWbemProcesses = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")

Do While bProcessFound
bProcessFound = FALSE
Set colWbemProcessesSet = oWbemProcesses.InstancesOf("Win32_Process")

For each process in colWbemProcessesSet
If process.ExecutablePath = strProcessString Then
strProcessName = process.Name
Wscript.Echo "Process " & process.Name & " running at " & Time
iTimesFound = iTimesFound + 1
If iTimesFound = 1 Then
strFirstFound = Time
End If
strLastSeen = Time
bProcessFound = TRUE
bFoundOnce = TRUE
Exit For
End If
Next
Wscript.Sleep iLoopInterval
Loop
Torgeir Bakken (MVP)
2005-04-28 15:13:40 UTC
Permalink
Post by ddebacker
Hello,
I'm trying to figure out how to check for the existence of a running
process using WMI inside a VBS file.
The problem I do have is that the process list I get from the WMI
class only contains the processes running under the user context that
launches the script (and the process I'm looking for is running in
another user context).
Is that an expected behaviour? If not, what should I do (I can't run
the VBS under the context that runs the process I'm looking for).
Can anyone help?
What I would like is to have the same kind of behaviour as the
TASKLIST.EXE (that lists ALL the processes running on the machine and
not only the ones running under the specific user context)
Here is how I do it (extract of the codes, some variables declaration
bProcessFound = TRUE
bFoundOnce = FALSE
strLastSeen = NEVER
strProcessName = strProcessString
iTimesFound = 0
Set oWbemProcesses = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
(snip)
Hi,

FYI: This group is closed and abandoned by Microsoft, you should ask
WMI/WBEM question in microsoft.public.win32.programmer.wmi instead.

Anyway:

See if taking the debug privilege helps (the user needs to have
administrator rights I think):

Set oWbemProcesses = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(debug)}!\\" _
& strComputer & "\root\cimv2")
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
Loading...