我的要求是获取azure 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上正常运行
请让我知道有人对此有解决方案。
答案 0 :(得分:0)
它可能与 Windows Management Instrumentation 服务处于停止状态有关。看看Starting and Stopping the WMI Service。
希望有帮助!