Managing Processes Sample
This sample uses objects in thenamespace to gather information about a running process.
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
To open the sample file in Solution Explorer
Click Download Sample.
The File Download message box appears.
Click Open, and on the left column of the zip folder window, click Extract all files.
The Extraction Wizard opens.
Click Next. You can change the directory that the files will be extracted to, and then click Next again.
Make sure that the Show extracted files check box is selected, and click Finish.
Double-click the sample's .sln file.
The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.
To run this sample
Click a process to have its details and thread data loaded. Use the menus to view the list of modules loaded by a particular process. Press F5 while the program is running to refresh the list of processes.
The processes on the current computer are displayed in acontrol by calling the method. When a process is selected, details about that process are shown in another ListView control. The process details are retrieved using the instance representing the process. The property is used to enumerate the threads of the process, which are then displayed in another ListView control. Each thread is represented by a instance. The modules for each process can be inspected by selecting a process and then clicking Modules in the main menu or the context menu. A separate form displays the modules loaded by the process and includes the name of the file where the code was loaded.
There are three processes that do not supply complete information:
_Total This process is added in code and does not represent a process. It is used to provide summary execution time, and processor utilization.
Idle Though returned as a process, it is not a process that can return data.
System This process does not expose module information.
You may not have access to all the information about a process. In that case, a message box is displayed.