please help me as i need to kill/ restart a process remotely.
I have tried this but no luck for me. Error was – “Couldn’t connect to remote machine”
Process[] prs = Process.GetProcesses("SERVERNAME");
foreach (Process pr in prs)
{
if (pr.ProcessName == "process")
{
pr.Kill();
}
}
I also try this one but still doesn’t work and got this error:
“Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))”
ManagementScope scope = new ManagementScope("\\\\SERVERNAME\\root\\cimv2");
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process WHERE Name='process'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection objectCollection = searcher.Get();
foreach (ManagementObject managementObject in objectCollection)
{
managementObject.InvokeMethod("Terminate", null);
}
I hope someone has a solution for this.Thanks in advance!
Well, the errors are actually telling you exactly what’s wrong. Your application is failed connecting to the remote machine. This can happen for some reasons:
Good luck.