请帮助我,因为我需要远程终止/重新启动进程。
我已经尝试过了,但对我来说没有运气。错误是 - “无法连接到远程机器”
Process[] prs = Process.GetProcesses("SERVERNAME");
foreach (Process pr in prs)
{
if (pr.ProcessName == "process")
{
pr.Kill();
}
}
我也尝试了这个,但仍然无法正常工作并收到此错误:“访问被拒绝。(来自 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);
}
我希望有人对此有解决方案。在此先感谢!