7

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);
harper
  • 13,345
  • 8
  • 56
  • 105

2 Answers2

3

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
  • 338,112
  • 86
  • 474
  • 445
  • 1
    Do you know a COM Object that provides the information in qeustion: The Identifier of the host process. – harper Aug 17 '10 at 15:02
  • @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 Aug 17 '10 at 15:10
  • 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 Aug 18 '10 at 06:14
2

You have the answer in DynamicWrapperX v1.0.

GargantuChet
  • 5,691
  • 1
  • 30
  • 41
  • 1
    Thanks for suggestion. It's a intering COM server. But since I have only to call one function, I could provide a COM server for this specific purpose. But I would have the same administrative effort to register the COM server. So the DynamicWrapperX doesn't help in this case. – harper Nov 08 '10 at 07:52