
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