Recipe6.4.Viewing the Running Processes


Recipe 6.4. Viewing the Running Processes

Problem

You want to see all processes that are currently running on a system.

Solution

Using a graphical user interface

  1. Open the Windows Task Manager (taskmgr.exe).

  2. Click on the Processes tab.

You can also accomplish the same task using the Sysinternals Process Explorer (procexp.exe) tool.

Using a command-line interface

There are several options for viewing the running processes via the command line. You can use tasklist.exe on Windows XP and Windows Server 2003 (use the /S option to target a remote system):

> tasklist

Another Windows XP and Windows Server 2003 tool that you can use to get a process list is wmic as shown here (use the /node: option to target a remote system):

> wmic process list brief

The Sysinternals pslist.exe utility is available for Windows Server 2003 or Windows 2000 and can be run against a remote host:

> pslist \\<ServerName>

There is also the top.exe command, which is available in the Windows 2000 Resource Kit. It provides a continually updated view of the top running process (by CPU):

> top

You can do something similar to top with pslist by specifying the -s option.


Using VBScript
' This code displays the running processes on the target computer. ' ------ SCRIPT CONFIGURATION ------ strComputer = "."  ' Can be a hostname or "." to target local host ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colProcesses = objWMI.InstancesOf("Win32_Process") for each objProcess In colProcesses     WScript.Echo objProcess.Name & " (" & objProcess.ProcessID & ")" next

Discussion

Sometimes it is difficult to associate an application (e.g., Internet Explorer) with its underlying process (e.g., iexplore.exe). In each of the command-line solutions, only the process name will be shown, which may be completely different from the name of the application. With Internet Explorer, it is pretty easy to figure out that iexplore.exe is probably the underlying process, but how can you tell for sure? One way is to look at Sysinternals Process Explorer. It displays a Description field that generally contains the application name of the process. Alternatively, you can specify the /v option with the tasklist command, which displays the Window Title field for each process. This typically includes the name of the application. Here is an example command you can run:

> tasklist /v /fo list

Unfortunately, there you can't retrieve the Window Title using the Win32_Process class.



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net