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.

RE: Retrieve ProcessID for the running script by urkec

urkec
Sat Dec 01 09:53:01 PST 2007

"CompGuy" wrote:

> 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.

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

RE: Retrieve ProcessID for the running script by CompGuy

CompGuy
Sat Dec 01 16:45:00 PST 2007

That did it!

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

"urkec" wrote:

> "CompGuy" wrote:
>
> > 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.
>
> 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