We are using a badly written windows service, which will hang when we are trying to Stop it from code. So we need to find which process is related to that service and kill i
I guess it's a two step process - if it's always the same service, you can easily find the process name using methods suggested in other answers.
I then have the following code in a class on a .NET 1.1 web server:
Process[] runningProcs =
Process.GetProcessesByName("ProcessName");
foreach (Process runningProc in runningProcs)
{
// NOTE: Kill only works for local processes
runningProc.Kill();
}
The Kill method can throw a few exceptions that you should consider catching - especially the Win32Exception, that is thrown if the process cannot be killed.
Note that the WaitForExit method and HasExited property also exist in the 1.1 world, but aren't mentioned on the documentation page for Kill in 1.1.