我的要求是获取安装的vm机器的软件详细信息并将详细信息存储在db中。但是当我尝试使用System.Management类获取详细信息时,我收到以下错误
System.Runtime.InteropServices.COMException:'RPC服务器不可用。 (HRESULT异常:0x800706BA)'
下面是我用来获取软件详细信息的示例代码
string SoftwareQuery = "SELECT * FROM Win32_Product";
ConnectionOptions connection = new ConnectionOptions();
connection.Username = "bla bla";
connection.Password = "Password";
connection.EnablePrivileges = true;
connection.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope managementScope = new ManagementScope(@"\\xxxx.xxxx.cloudapp.azure.com:3389\root\CIMV2", connection);
managementScope.Path = ManagementPath.DefaultPath;
managementScope.Connect();
ObjectQuery queryObj = new ObjectQuery(SoftwareQuery);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope, queryObj);
foreach (ManagementBaseObject managementObj in searcher.Get())
{
//get the software list here
}
注意:上面的代码正在适当地在Intranet上工作
请让我知道有人有解决方案。
它可能与Windows Management Instrumentation服务处于停止状态有关。看看Starting and Stopping the WMI Service。
希望能帮助到你!