"David E. Ross" <***@not_there.invalid> wrote
| > Does it need to be command line? Sysinternals
| > process explorer will give you both.
|
| I wanted a command line method to incorporated into a DOS-type script.
|
I see. I've done a lot with WMI but I'm not familiar with
the commandline version, WMIC. In case it's of any use,
here's a short VBScript version that you might be able to
adapt to WMIC. It enumerates items in the Win32_Process
class. The list of available properties is vast but mostly useless.
(See the WMI help file.) There are also methods, like Terminate.
This sample just gets EXE path and PID. I've left an error trap
in the code because using WMI depends on 2 services --
Windows Management Instrumentation and DCOM Server Process
Launcher. If those are disabled WMI will not be accessible.
They could be disabled in some corporate settings. (I'd
disable them myself if it were not for the fact that I use
WMI. Aside from cheap system utilities, there's rarely any
reason for anyone to need WMI running and it's a potential
security risk. As is Power Shell.)
You might be able to run this via cscript, or run it and
return the data to your commandline, or maybe run it in
batch (via Power Shell?) if you can figure out the corresponding
syntax for that. But as I say, I don't have any experience
with those options. If you paste the following into Notepad
and save as a .vbs file you can see how it works.
'----begin VBS
On Error Resume Next
Dim WMI, S2, Col
Set WMI = GetObject("WinMgmts:")
If (Err.number <> 0) Then
MsgBox "Error creating WMI object. Error: " & Err.Number & " - " &
Err.Description
WScript.quit
End If
Set Col = WMI.ExecQuery("Select * from Win32_Process")
S2 = S2 & " Process Info:" & vbCrLf & vbCrLf
For Each Ob in Col
S2 = S2 & "Caption: " & Ob.Caption & vbCrLf
S2 = S2 & "ExecutablePath: " & Ob.ExecutablePath & vbCrLf
S2 = S2 & "ProcessID: " & Ob.ProcessID & vbCrLf &
"__________________________" & vbCrLf & vbCrLf
Next
Set Col = Nothing
Set WMI = Nothing
MsgBox S2