Solution 1:
Write an agent program that will be deployed on each remote machine.
Write your C# application using to do:
- grab the list of all connected machines
- select a remote machine name and sent a query to extract the list of all running processes
- select the process or processes to be killed or stopped (services)
- send the list (name) of the selected processes to the agent
- upon receiving the list of processes the agent will do:
- find the process by name. If it is running then kill it using Process.Kill() if the process has no graphical interface else use CloseMainWindow() and if that fails call Kill(). If the process is a running service you can stop it only. In order to do that, the agent should use Process and ServiceController classes.
Solution 2:
Create C# application using :
-Process class to read the running processes on the local/remote machine and kill them.
-ServiceController class to read the running services and device drivers on the local/remote machine and stop/start them.
Code:
Process[] arrProcess=Process.GetProcesses(strMachineName);
Process tmp= Process.GetProcessById(Int32.Parse (strKey),strMachineName);
Process tmp=Process.GetProcessByName(strProcName);
pSelectedProcess.Kill();
//Intercept the exit using an event handler for each process to kill
Code:
tmp.Exited += new EventHandler(OnProcessExited);
private void ProcessExited(object sender, EventArgs e)
{
Process tmp2 = (Process)sender;
MessageBox.Show(tmp2.ProcessName + " ID: " + tmp2.Id.ToString() + " is exiting");
}
//ServiceController
//Load services
ServiceController[]arrSrv;
arrSrv= ServiceController.GetServices(strMachineName);
//..
foreach(ServiceController srv in arrSrv)
{
// check the srv.Status
if(srv.CanStop)
{
try
{
srv.Stop(); System.Threading.Thread.Sleep(500);
while(srv.Status == ServiceControllerStatus.StopPending)
{
Application.DoEvents();
}
}
}
}
/..
[/code]
obislavu