tags:

views:

50

answers:

2

I would like to obtain the current process id in a JScript script. This id is returned by the Windows API GetCurrentProcessId (http://msdn.microsoft.com/en-us/library/ms683180.aspx) function. How do I call this function in JScript?

This obviously doesn't work:

var id = GetCurrentProcessId();
WScript.Echo("ProcessId is " + id);
A: 

Windows APIs aren't made available to the JScript runtime. You're limited to methods and properties listed in the MSDN JScript language reference, although you can also connect to WMI and create instances of COM Objects to extend beyond JScript's limitations.

Andy E
Do you know a COM Object that provides the information in qeustion: The Identifier of the host process.
harper
@harper: I'm not aware of one. You could use WMI to get the process ID of wscript.exe (which is the host process), but if there are multiple scripts running this could create multiple processes and you wouldn't know which one belonged to your script.
Andy E
@Andy: No. I can't. The script will be hosted in most cases by CScript.exe. That goal is to identify the host. Therfor I tried to enumerate the processes with WMI/W32_Process and identify the own process.
harper