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


Comments

  • killing process not working in localhost

    Posted by bikashroutray on 07/12/2007 02:44am

    Hi, 
    I am implemented the single solution on my windows XP machine as client as well as server. 
    
    But when i am trying to kill the process i am getting the following error :
    An unhandled exception of type
    'System.Runtime.Serialization.SerializationException' occured in mscorlib.dll
    Additional information: Because of security restrictions, the type
    System.Runtime.Remoting.ObjRef cannot be accessed.
    
    Can anyone help me on this?
    
    Thanks
    Bikash

    Reply
  • Running the ExecServer as a service

    Posted by torel on 07/14/2005 09:59am

    What would it take to run the application as a service on the remote computer? The reason for this question is toA be able to submit jobs without the need to be logged in on the remote computer. As far as I know, only a service can be loaded prior to logging in on a computer? Any hints on how to do this? best regards Tore

    Reply
  • killing process is not working]

    Posted by anilmane on 10/26/2004 02:26pm

    hello gurus I have checked at my place is working fine in network. works very fine. But when i use kill process it gives error which is not working fine Could you please guide me. Thanks Anil M.

    Reply
  • Can i give IP in the server name?

    Posted by Legacy on 02/26/2004 12:00am

    Originally posted by: venkat

    In the place of server name can i type the IP address of the remote machine(not in the same domain) and still continue using like this?

    regards
    Venkat

    • Yes IP Address will work

      Posted by suniltg on 04/21/2004 07:44am

      Because this is designed to run over the internet, best idea is to give IP address rather than machine name. Sunil

      Reply
    Reply
  • Thanks

    Posted by Legacy on 11/14/2003 12:00am

    Originally posted by: Michael Hardt

    Just wanted to add my thanks for this outstanding sample. It's been very useful for me.

    Reply
  • Process.Kill() does not seem to work across remote machines

    Posted by Legacy on 04/20/2003 12:00am

    Originally posted by: Andy

    When I call Process.Kill() on the client, the server object throws a remoting exception. Any help would be useful.

    Reply
  • Great Work

    Posted by Legacy on 04/04/2003 12:00am

    Originally posted by: Dipin

    Its a great work .It will very useful. I thank to Sunil for such programs.
    

    Reply
  • Very good example

    Posted by Legacy on 03/26/2003 12:00am

    Originally posted by: akolev

    It's very good example on .Net remoting.I wish to know where there are more exapmles like this about .Net remoting ( besides www.codeguru.com and www.codeproject.com )

    Reply
  • Quite useful

    Posted by Legacy on 12/05/2002 12:00am

    Originally posted by: Sameer

    This application is helping me to understand concepts of client/server. Being new to this, I am finding this quite useful. Many thanks.

    Reply
  • great work.very informative !!

    Posted by Legacy on 11/28/2002 12:00am

    Originally posted by: ravindranath

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Confused by all the agile advice? Relax! With the Agile for Dummies eBook by your side you'll learn the fundamentals of agile and how to increase the productivity of your software teams while enabling them to produce higher-quality solutions that better fulfill customer needs much faster.

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds