How do I determine my own Process ID (PID) 
Author Message
 How do I determine my own Process ID (PID)

I have looked high and low thru this newsgroup, web sites and the WSH and
VBScript help files and cannot find *anywhere* where the Process ID of the
currently running process is provided...am I missing something or is
something so easy to determine (in the UNIX world) just *missing* from the
W2K world?

I realize I can probably do a select on Win32_Process and figure it out that
way, but what a pain...there is *got* to be an easier way...

Thanks in advance.

Andrew D. Fields



Sat, 28 Aug 2004 08:11:25 GMT  
 How do I determine my own Process ID (PID)

Quote:

> I have looked high and low thru this newsgroup, web sites and the WSH and
> VBScript help files and cannot find *anywhere* where the Process ID of the
> currently running process is provided...am I missing something or is
> something so easy to determine (in the UNIX world) just *missing* from the
> W2K world?

> I realize I can probably do a select on Win32_Process and figure it out that
> way, but what a pain...there is *got* to be an easier way...

You'd better find excuse of why is pain good for you and/or why you are prepared
to like it - as you *will* be feeling it a qute a bit - should you decide to adopt
Microsoft views on (administrative?) scripting. Windows scripting is geared towards
"do-it-yourself-ers" (somewhat pathetic folks with plenty of time on their hands),
in other words - you *will* have to deal with tons of ugly details you normally
shouldn't/wouldn't need to know about in *NIX world.

Run away screaming while you still can, or be prepared to dive in "that stuff"...

You could also resort to (much) more powerful scripting languages (Python or Perl)
and free yourself of chore of having to re-invent wheel for almost every nontrivial
task you want to perform. Even with this arguably smarter approach, there still
*will* be plenty of opportunities to deal with "MS monsters". Some of these - like
WMI or ADSI happen to be extremely useful (thus unavoidable) beasts in Win* environment
(which further reinforces While(FeelThePain==true) LearnToLoveIt();  loop).

Example of how to list running processes using WMI (present by default on Win2K
and WinXP systems):

Sub ListLocProcessess()
 Dim vProcess, sMsg
 for each vProcess in GetObject("winmgmts:{impersonationLevel=impersonate,(Debug)}").InstancesOf("win32_process")
  sMsg = sMsg & vProcess.ProcessId & vbTab & vProcess.name & vbCrLf
 next
 WScript.Echo sMsg
End Sub

Branimir



Sat, 28 Aug 2004 10:38:58 GMT  
 How do I determine my own Process ID (PID)

It's a problem.

Since you *can* get a PID for a file you launch via Exec (after you have launched it...) the method I used is to have a "starter" script which launches another script and gives it an arbitrary filename as a parameter. The second script hangs around until it sees the file, then reads it to find out what its own PID is.

I have a file pair attached which will do this as an example.  The "elegant" way to do it is to integrate both into the same WSF (you could even do it as a pure VBScript with some finagling involving arguments supplied).  Not pretty, but it works.

: I have looked high and low thru this newsgroup, web sites and the WSH and
: VBScript help files and cannot find *anywhere* where the Process ID of the
: currently running process is provided...am I missing something or is
: something so easy to determine (in the UNIX world) just *missing* from the
: W2K world?
:
: I realize I can probably do a select on Win32_Process and figure it out that
: way, but what a pain...there is *got* to be an easier way...
:
: Thanks in advance.
:
: Andrew D. Fields

:
:
:

  IKnowMyPID.wsf.txt
2K Download

  sleeper.vbs.txt
< 1K Download


Sat, 28 Aug 2004 10:50:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VB on NT process id / pid

2. Detecting Own Process ID

3. Detecting Own Process ID

4. finding own Process ID

5. How a 32-Bit App Can Determine When a Shelled Process Ends, Article ID: Q129796

6. API call to determine number of open Handles per process ID

7. own PID

8. How to get my own PID ?

9. When does the Word PID (Product ID change)

10. Getting the PID / Task ID of running program

11. Control process ID and Thread ID

12. Parent ID of a given Process ID under NT 4.0

 

 
Powered by phpBB® Forum Software