Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Retrieve ProcessID for the running script

1,293 views
Skip to first unread message

CompGuy

unread,
Dec 1, 2007, 10:23:00 AM12/1/07
to
I am able to retrieve the ProcessID for processes using the Win32_Process
Class, however I am not able to retrieve the ProcessID for the script that
the code is running in. I can't use the Name of the process since I have
multiple wscript.exe running so the only way I can think of getting the
ProcessID is by finding properties for the current script process only. I
have no idea how to do this since the closest I can get is a complete list of
running processes while I just need the info for the currently running script.

Any help with this issue would be greatly appreciated.

urkec

unread,
Dec 1, 2007, 12:53:01 PM12/1/07
to
"CompGuy" wrote:

I used Win32_Process.CommandLine property and it seems to work with both
wscript.exe and cscript.exe.

Set objSWbemServices = GetObject ("WinMgmts:Root\Cimv2")
Set colProcess = objSWbemServices.ExecQuery _
("Select * From Win32_Process")

For Each objProcess In colProcess
If InStr (objProcess.CommandLine, WScript.ScriptName) <> 0 Then
WScript.Echo objProcess.Name, _
objProcess.ProcessId, _
objProcess.CommandLine
End If
Next


--
urkec

CompGuy

unread,
Dec 1, 2007, 7:45:00 PM12/1/07
to
That did it!

Thank you very much urkec, now I can finish my work.

0 new messages