Manage Processes on Remote Machines over the Net-Remote Process Manager

Environment: Visual Studio .NET—C#, Windows 2000/XP

Remote process manager is an application that is useful for starting and killing processes on machines over the network (Internet). There is a Remote Process Invoker Server application, which must be run on the machine on which we want to manage the processes, and a client application that provides the UI.

This project will help readers understand the basics of .NET remoting, Win UI programming in C#, and the System.Diagnostics namespace. .NET Remoting is used in this project to bring Process objects on a remote machine to the client machine.

There are three binaries in ProcRunner.dll, which contains the object that is being remoted by the ExecServer.exe application, which is to be run on the machine in which processes are to be managed remotely. The ExecClient.exe application is run as the client program, which provides the user with a UI to start and stop processes on the remote machine. This application also lists the details of running processes on the remote machine.

The ProcRunner.dll the CprocRunner class has the functionalities of starting, stopping, and getting a list of running processes.

Here is a simple piece of code for starting a process with arguments:

public bool RunProcess(string strProgramName, string strArgs)
{
  Process proc = new Process();
  proc.StartInfo.FileName = strProgramName;
  if (strArgs != string.Empty)
    proc.StartInfo.Arguments = strArgs;
  proc.Start();
}

To get the processes' list :

Process[] process = Process.GetProcesses();

ExecServer is a Windows application that simply hosts the ProcRunner object. This object is being remoted as a singleton. A tray icon will be shown when the server is run, as shown in the following figure.

The client application simply creates an object of CProcRunner, and calls the GetProcesses(), Kill(Process), and RunProcess(ProcessName, Args) methods.

Remoting Configuration

The remoting configuration for the two exes is provided with the help of two application configuration files. No change for the server exe's config file is needed. But, before running the client, change the URL field in the app config file to point to the server machine's URL .

wellknown type="ProcRunner.CProcRunner,ProcRunner"
          url="tcp://[SERVER MACHINE NAME]:7500/ProcRunner"

How to Build and Run the Project

Unzip the code to a folder. Open the solution in the "SingleSolution" folder, and build the solution. By default, the client app config file will point to the remote object on the "localhost" machine. Now, you can run the client and server on the same machine. For managing processes on a remote machine, run the server in that machine, and run the client from your local machine AFTER editing the client config file and making it point to the url of the server. Refer to "Remoting Configuration" above.

Downloads

Download demo project - 25 Kb
Download source - 62 Kb