ProcessController Sample: Demonstrates Processes and Services Monitoring
This documentation is archived and is not being maintained.

ProcessController Sample: Demonstrates Processes and Services Monitoring

Visual Studio .NET 2003

The ProcessController sample shows how to build a C# Windows application for processes and services monitoring. The sample also demonstrates the following activities:

  • Dynamically adding and removing event handlers.
  • Using the Process component to:
    • Read the running processes on the local/remote machine.
    • Start a process on the local machine.
    • Stop a process on the local/remote machine.
    • Read the modules used by some running process.
    • Read all of the characteristics of some running process.
  • Using the ServiceController component to:
    • Read the running services and device drivers on the local/remote machine.
    • Start/Stop/Pause a service on the local/remote machine.
    • Check properties of the services or device drivers on the local/remote machine.
  • Handling security issues related to the use of the Process and the ServiceController components.
Note   This sample only runs on the Windows NT or Windows 2000 operating systems since the ServiceController component is only supported on Windows NT platforms.

Building and Running the Sample

To build and run this sample

  1. Open the solution ProcessController.sln.
  2. From the Build menu, click Build Solution.
  3. From the Debug menu, click Start Without Debugging.

    The main application window will appear.

The following figure shows the ProcessController program running. Refer to the figure, as needed, while you perform the following test procedures:

  • Load all services, device drivers, and processes running on some machine in the network.
  • Start/Pause/Stop a service or a device driver running on the local/remote machine.
  • Start a process running on the local machine.
  • Terminate a process running on the local/remote machine.

Process Controller

Aa645519.vcprocesscontroller1(en-us,VS.71).gif

To load all of the services, device drivers, and processes

  1. Type the name of the machine you want in the Machine Name box.
  2. Click the Load Data button (or press ALT+L).

To start a service

  1. Click a service name in the Stopped Services list.
  2. Right-click the service and click Start Service from the shortcut menu.

    After the service starts, its name should appear in the topmost list labeled Running Services.

    Note   You cannot start a service if you do not have the administrator rights on that machine.

To stop a service

  1. Click a service name in the Running Services list.
  2. Right-click the service and click Stop Service from the shortcut menu.

    After the service has been stopped, the name should appear in the Stopped Services list.

    Note   Some services do not accept the Stopped state. Also, you cannot stop a service if you do not have the administrator rights on that machine.

To pause a running service

  1. Click a service name in the Running Services list.
  2. Right-click the service and click Pause from the shortcut menu.

    If the service is paused, the service name should appear in the Paused Services list at the bottom of the window.

    Note   Some services do not accept the Paused state. Also, you cannot pause a service if you do not have the administrator rights on that machine.

To check some of the service's information

  1. Click a service name in any of the three lists.
  2. Right-click the service and click Show Service Info from the shortcut menu. A new window containing the service information will appear.

To verify and manage device drivers

  1. Click the Drivers tab at the top of the window.
  2. Go through the preceding steps to start, stop, and pause a service. Exactly the same rules mentioned for services apply to the device drivers.

To verify and manage processes

  1. Click the Process tab at the top of the window.
  2. Select a process name in the leftmost list. At this point, information about that service should appear in the list on the right.

    Note   If you are not an administrator on the target machine, you will not be able to see or manage any process.

To start a process

  1. Click the Start a Process button (or press ALT+S).
  2. Select the process you want to start in the Open dialog box.
  3. Click the Open button in the dialog box. If your target machine is the local machine, the process name should appear in the leftmost list.

    Note   If the target machine is a remote machine, the process will start on the local machine, by default, if possible.

To stop a process

  1. Click a process in the leftmost list.
  2. Right-click the process and click Terminate Process from the shortcut menu.

    After the process has been terminated, its name should disappear from the list.

To load the services, drivers, and processes from another machine

  1. Type the name of the machine in the Machine Name box.
  2. Click the Load Data button (or press ALT+L).

To stop the ProcessController application

  • Click the Close Application button (or press ALT+C).

    After you click the button, the window will slowly fade away. This effect is obtained by handling the Windows Opacity property (file: MainForm.cs, method: cmdClose_Click).

Description of the Sample Classes

FileDescription
MainForm.csDescribes the MainForm class, which is a System.Windows.Forms.Form type class. Its designer contains most of the UI controls needed for this application.
ProcessControllerManager.csContains the implementation of the ProcessControllerManager class. This class handles processes management.
DriverControllerManager.csContains the implementation of the DriverControllerManager class. This class is in charge of managing the device drivers on a given machine.
ServiceControllerManager.csContains the implementation of the ServiceControllerManager class. This class describes the logic to control the services on a given machine.
ServiceInfo.csImplements the ServiceInfo class, which is a System.Windows.Forms.Form class and is used to display services and drivers information only.

Classes and Keywords

This sample demonstrates the following classes:

System.Windows.Forms.Form, System.Windows.Forms.TabControl, System.Windows.Forms.ListBox, System.Windows.Forms.TabPage, System.Windows.Forms.OpenFileDialog, System.Collections.Hashtable, System.Windows.Forms.Timer, System.EventHandler, System.Windows.Forms.ContextMenu, System.Diagnostics.Process, System.ServiceProcess.ServiceController

This sample demonstrates the following keywords:

C# Windows Application; Process component; ServiceController component; C# Class inclusion; TabControl and TabPage; Event Handler dynamic load; ListView control; ContextMenu control and MenuItems; HashTable object; Timer control; System security issues; System.Array.Sort

See Also

Visual C# Samples | General Samples | Windows Forms: Process Controller Sample (Visual Basic)

Show:
© 2016 Microsoft