我運行下面的代碼:System.Management.ManagementException:未找到
ManagementClass oMClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection colMObj = oMClass.GetInstances();
這是引發此異常:
System.Management.ManagementException: Not found
at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementClass.GetInstances(EnumerationOptions options)
at System.Management.ManagementClass.GetInstances()
我去檢查在Windows XP和正在運行的服務發現Windows Management Instrumentation服務的狀態爲「已啓動」。我嘗試重新啓動服務,但沒有任何好處。 然後我試圖從使用ServiceController的類我正在運行的代碼中得到這個服務的狀態:
ServiceController wpiService = new ServiceController();
wpiService.ServiceName = "Winmgmt";
string wmiStatus = wpiService.Status.ToString();
MessageBox.Show("WMI status= " + wmiStatus);
wmiStatus評估爲「正在運行」。
我只在運行相同軟件的多臺機器中的一臺上看到了此錯誤。奇怪的是,這臺機器運行平穩了好幾個月,然後突然開始顯示這個錯誤。
任何線索可能是什麼原因造成的?
感謝您修復WMI的鏈接!我的一個客戶端是XP sp3,我首先嚐試過「rundll32 wbemupgd,UpgradeRepository」,但它返回錯誤(找不到對象/名稱空間)。然後,我試着「停止winmgmt->重命名庫 - >啓動winmgmt」,這是有效的,再次感謝! – AlexanderYao