How Do I...Get information about processes?

Please note that this sample might fail on Windows 95 or Windows 98 machines.

You can use the Process component to accomplish most process management tasks quickly and easily. You can use this component to work with processes on either local or remote computers. For example, you can query a process for specific types of information, including the names of the modules it is loaded into, the time it was started, the number of handles it is consuming, and the set of its threads.

This sample illustrates how to get a simple information about a process. It is a small console application that you can run from a command prompt. Run the sample without any command line arguments and it will print its full usage instructions.

For example, if you want to enumerate all processes on your machine, run:

> PrInfo.exe e

If you want to show the most common information about a process, run the sample with the "i" option with a process id. Remember to substitute a real process id for "125".

> PrInfo.exe i 125

In its simplest form, getting information about a process involves:

  1. Creating a new instance of a Process component and pointing it to a process running on your system:

    
    Dim process As Process = Process.GetProcessById(processid)
    
    VB

  2. Reading the desired property of the Process component:

    
    Console.WriteLine("Priority: " & process.PriorityClass.ToString())
    
    VB

Example

 
VB PrInfo.exe

[Run Sample] | [View Source]


Copyright 2001 Microsoft Corporation. All rights reserved.