当前状态:
ObjectQuery queryObj = new ObjectQuery("SELECT * FROM Msvm_ComputerSystem");
ConnectionOptions connOpts = new ConnectionOptions();
connOpts.Username = @"DOMAIN\ADMINISTRATOR";
connOpts.Password = "PASSWORD";
connOpts.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(@"\\IP_OF_SERVER\root\virtualization\v2", connOpts);
//ManagementScope manScope = new ManagementScope(@"\\.\root\virtualization\v2");
manScope.Connect();
// connect and set up our search
ManagementObjectSearcher vmSearcher = new ManagementObjectSearcher(manScope, queryObj);
ManagementObjectCollection vmCollection = vmSearcher.Get();
// loop through the VMs
foreach (ManagementObject vm in vmCollection)
{
// display VM details
Console.WriteLine("\nName: {0}\nStatus: {1}\nDescription: {2}\n",
vm["ElementName"].ToString(),
vm["EnabledState"].ToString(),
vm["Description"].ToString());
}
在初始化ManagementScope并用.
交换服务器的IP并在服务器上本地运行程序时,我可以读取VM数据。但是,当使用附带的IP远程执行代码时,我收到一个UnauthorizedAccessException
,说它是not supported
。在ManagementScope.Connect()
处引发了异常。
我怎么了?
谢谢!
EDIT:看来问题出在我们的网络/服务器的配置之内,因为即使简单地查询机器进程也会失败。我必须等到配置了远程访问并尽快更新请求。
EDIT2:问题出在我们的网络内,必须将WMI配置为进行远程访问。线程可以关闭。