我正在尝试使用WMI停止远程计算机上的进程
try
{
ConnectionOptions connectionOptions = new ConnectionOptions();
connectionOptions.Username = IFS_username;
connectionOptions.Password = IFS_password;
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope("\\\\" + IFS_IP + "\\root\\CIMV2", connectionOptions);
scope.Connect();
ManagementPath path = new ManagementPath("Win32_Process");
ManagementClass services;
services = new ManagementClass(scope, path, null);
foreach (ManagementObject service in services.GetInstances())
{
if (service.GetPropertyValue("Name").ToString().ToLower()=="notepad.exe")
{
service.InvokeMethod("Terminate", null);
}
}
}
catch (Exception ex)
{ textBox1.Text = ex.ToString(); }
}
但是我得到了以下异常
System.Runtime.InteropServices.COMException (0x800706BA):
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementScope.Connect()
将一些乱七八糟的事情改为
之后enter code here
我检查了几页,似乎我的方法是正确的,但我无法找到异常的解决方案。