I use this code to look at properties of a process

Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process
...")
For Each objItem in colItems
Wscript.Echo objItem.Name
...

The Name or Caption property shows the command such as notepad.exe.
ExecutablePath shows the full path. If the process is "notepad
myfile.txt", how do I see "myfile.txt"? I looked at all properties of
Win32_process and none shows that info. Thanks for help.

Yong Huang

Re: Any way to get running process command argument? by Stan

Stan
Tue Jul 20 17:56:31 CDT 2004

Yong,

Take a look here:
http://www.devguru.com/Technologies/wsh/quickref/wscript_Arguments.html.
WScript.Arguments returns the collection to you.

Stan Scott
New York City

"Yong Huang" <yong321@yahoo.com> wrote in message
news:b3cb12d6.0407201252.30d31d2@posting.google.com...
> I use this code to look at properties of a process
>
> Set objWMIService = GetObject("winmgmts:" & _
> "{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
> Set colItems = objWMIService.ExecQuery("Select * from Win32_Process
> ...")
> For Each objItem in colItems
> Wscript.Echo objItem.Name
> ...
>
> The Name or Caption property shows the command such as notepad.exe.
> ExecutablePath shows the full path. If the process is "notepad
> myfile.txt", how do I see "myfile.txt"? I looked at all properties of
> Win32_process and none shows that info. Thanks for help.
>
> Yong Huang



Re: Any way to get running process command argument? by Michael

Michael
Tue Jul 20 19:08:06 CDT 2004

Yong Huang wrote:
> I use this code to look at properties of a process
>
> Set objWMIService = GetObject("winmgmts:" & _
> "{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
> Set colItems = objWMIService.ExecQuery("Select * from Win32_Process
> ...")
> For Each objItem in colItems
> Wscript.Echo objItem.Name
> ...
>
> The Name or Caption property shows the command such as notepad.exe.
> ExecutablePath shows the full path. If the process is "notepad
> myfile.txt", how do I see "myfile.txt"? I looked at all properties of
> Win32_process and none shows that info. Thanks for help.


For XP and higher...

Win32_Process.CommandLine

Win32_Process
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_process.asp

--
Michael Harris
Microsoft.MVP.Scripting
Sammamish WA US

Re: Any way to get running process command argument? by Torgeir

Torgeir
Wed Jul 21 04:16:55 CDT 2004

Michael Harris (MVP) wrote:

> Yong Huang wrote:
>
>>I use this code to look at properties of a process
>>
>>Set objWMIService = GetObject("winmgmts:" & _
>>"{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
>>Set colItems = objWMIService.ExecQuery("Select * from Win32_Process
>>...")
>>For Each objItem in colItems
>> Wscript.Echo objItem.Name
>>...
>>
>>The Name or Caption property shows the command such as notepad.exe.
>>ExecutablePath shows the full path. If the process is "notepad
>>myfile.txt", how do I see "myfile.txt"? I looked at all properties of
>>Win32_process and none shows that info. Thanks for help.
>
>
>
> For XP and higher...
>
> Win32_Process.CommandLine
>
> Win32_Process
> http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_process.asp


And for Windows 2000:

For Win2k, if you want to get to the command line property for
a process, you can use tlist.exe in the Win2k "Support Tools".
If you run "tlist.exe <pid>", it will be listed for the process
with that PID. From a VBScript, you would need to parse this output.

E.g. here is the output for AutoItX's help file process running on my
computer just now:

C:\>tlist 2428
2428 hh.exe AutoItX Help
CWD: F:\wsh\AutoItX\AutoItX\
CmdLine: "C:\WINNT\hh.exe" F:\wsh\AutoItX\AutoItX\AutoItX.chm
(snip)


tlist .exe for Win2k is in the Support Tools found on the Win2k CD,
\Support\Tools\Suptools.msi, or for the latest version of
Support Tools (should work on non-SP4 computers as well):

http://www.microsoft.com/windows2000/downloads/servicepacks/sp4/supporttools.asp

--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Any way to get running process command argument? by yong321

yong321
Wed Jul 21 09:25:12 CDT 2004

"Michael Harris \(MVP\)" <mikhar at mvps dot org> wrote in message news:<e0jmNbrbEHA.1004@TK2MSFTNGP11.phx.gbl>...
> Yong Huang wrote:
> > I use this code to look at properties of a process
> >
> > Set objWMIService = GetObject("winmgmts:" & _
> > "{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
> > Set colItems = objWMIService.ExecQuery("Select * from Win32_Process
> > ...")
> > For Each objItem in colItems
> > Wscript.Echo objItem.Name
> > ...
> >
> > The Name or Caption property shows the command such as notepad.exe.
> > ExecutablePath shows the full path. If the process is "notepad
> > myfile.txt", how do I see "myfile.txt"? I looked at all properties of
> > Win32_process and none shows that info. Thanks for help.
>
>
> For XP and higher...
>
> Win32_Process.CommandLine
>
> Win32_Process
> http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_process.asp

Thank you, Michael. I listed all Names and Values of Properties_ of a
Win32_Process instance running on my Windows 2000. That's why I didn't
see the CommandLine property. I should have looked it up in
documentation. Is it possible to upgrade just a small portion of WMI
on my machine to get this working? It looks like on Windows 2000, some
Win32 programming may be necessary to get this information.

Yong Huang

Re: Any way to get running process command argument? by yong321

yong321
Wed Jul 21 14:38:46 CDT 2004

"Torgeir Bakken \(MVP\)" <Torgeir.Bakken-spam@hydro.com> wrote in message news:<#Oxo$OwbEHA.2840@TK2MSFTNGP11.phx.gbl>...
> ...
> And for Windows 2000:
>
> For Win2k, if you want to get to the command line property for
> a process, you can use tlist.exe in the Win2k "Support Tools".
> If you run "tlist.exe <pid>", it will be listed for the process
> with that PID. From a VBScript, you would need to parse this output.
>
> E.g. here is the output for AutoItX's help file process running on my
> computer just now:
>
> C:\>tlist 2428
> 2428 hh.exe AutoItX Help
> CWD: F:\wsh\AutoItX\AutoItX\
> CmdLine: "C:\WINNT\hh.exe" F:\wsh\AutoItX\AutoItX\AutoItX.chm
> (snip)

Thanks, Torgeir. Is there a way to store the output of running a
command such as tlist in a variable (byte stream, character array
etc.)? Unless I have to, I don't want to redirect to a file and parse
it later.

Yong Huang