Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: How to get the pid of the current running script and parent proces

HTVi
TV Discussion Newsgroups

How to get the pid of the current running script and parent proces
Wizard 7/11/2007 11:56:00 PM
Sorry, I am not a power shell user (YET). I am using cscript

I have tried the following and it did not work for the oShell.ProcessID.

When I exec the process, it returns the PID.... Why?


How do I get the current process ID, so I can perform actions on all of the
processes in the system but the current process AND some of the other
selected processes like windows itself etc.

var oShell = WScript.CreateObject( "WScript.shell" );
var oNet = WScript.CreateObject( "WScript.Network" );
var strComputer = oNet.ComputerName;
WScript.Echo( "The computer name is ",strComputer);
WScript.Echo( "The PID is ",oShell.ProcessID);
var oCalc = oShell.Exec("calc");
WScript.Echo( "The PID is ",oCalc.ProcessID);


--
John
Re: How to get the pid of the current running script and parent proces
"Michael Harris \(MVP\)" <mikhar.at.mvps.dot.org> 7/12/2007 1:04:34 AM
Wizard wrote:
[Quoted Text]
> Sorry, I am not a power shell user (YET). I am using cscript
>
> I have tried the following and it did not work for the
> oShell.ProcessID.
>
> When I exec the process, it returns the PID.... Why?

Because that is simply how the object returned by the WshShell.Exec method
is designed...

>
>
> How do I get the current process ID, so I can perform actions on all
> of the processes in the system but the current process AND some of
> the other selected processes like windows itself etc.
>
> var oShell = WScript.CreateObject( "WScript.shell" );
> var oNet = WScript.CreateObject( "WScript.Network" );
> var strComputer = oNet.ComputerName;
> WScript.Echo( "The computer name is ",strComputer);
> WScript.Echo( "The PID is ",oShell.ProcessID);
> var oCalc = oShell.Exec("calc");
> WScript.Echo( "The PID is ",oCalc.ProcessID);

On XP and later, the Win32_Process objects that you can get with an
ExecQuery call have a CommandLine property along with the ProcessId (same as
Handle) and ExecutablePath from pre-XP WMI versions. Note that CommandLine
and Executable path may be Null on some Win32_Process instances.

This is a vbscript example but easy enough to port to jscript...

Set wmi = GetObject("winmgmts://./root/cimv2")
Set processes = wmi.execQuery(_
"select Handle, Caption, CommandLine, ExecutablePath " _
& "from win32_process")
For Each process In processes
with process
wscript.echo .Handle, .Caption, .CommandLine, .ExecutablePath
End with
Next

--
Michael Harris
MVP - Admin Frameworks


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen