2013-08-23 45 views
0

我有C#代碼,試圖從WMI對象 - Win32_Service加載一些屬性。但它返回給我'System.Management.ManagementException:無效的類'錯誤。Win32_Service丟失

我的簡化代碼:

static void Main(string[] args) 
{ 
    string serviceName = "AppFabricEventCollectionService"; 
    string propertyName = "StartName"; 
    var obj = GetProperty(serviceName, propertyName); 
} 

private static string GetProperty(string serviceName, string propertyName) 
{ 
    using (ManagementObject obj2 = GetWindowsServiceManagementObject(serviceName)) 
    { 
     return (obj2.GetPropertyValue(propertyName) as string); 
    } 
} 
public static ManagementObject GetWindowsServiceManagementObject(string serviceName) 
{ 
    return new ManagementObject(string.Format("Win32_Service.Name='{0}'", serviceName)); 
} 

而且我已經嘗試通過PowerShell命令加載WMI對象的列表 -

GET-WmiObject可以 - 列出|選擇名稱

它返回91個對象,但它錯過了Win32_Service對象。我搜索瞭如何重新安裝它,但沒有找到它。有沒有辦法重新安裝它?

謝謝

更新1: 輸出的PowerShell命令:

PS C:\Windows\system32> Get-WmiObject Win32_Service 
Get-WmiObject : Invalid class "Win32_Service" 
At line:1 char:1 
+ Get-WmiObject Win32_Service 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidType: (:) [Get-WmiObject], ManagementExce 
    ption 
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.C 
    ommands.GetWmiObjectCommand 
+0

在PowerShell中,確實'GET-WmiObject可以win32_service時|選擇名稱「工作? – nimizen

+0

不。它不起作用。我將輸出添加到Update 1中 –

+0

這是什麼操作系統? – nimizen

回答

1

參看 「我得到一個0x80041010(‘無效類’)錯誤」 here。您可能會發現一些有用的東西,特別是使用​​和Wbemtest

+0

我試過wbemtest。但是當我點擊Connect時,它顯示錯誤信息:「Number:0x80040154 Facility:Interface Description:Class not registered」 –

0

請嘗試重新註冊的基類(管理員命令行,當然...)

mofcomp %windir%\system32\wbem\cimwin32.mof 
+0

我發現cimwin32.mof的唯一地方是C:\ Windows \ winsxs \ amd64_microsoft-windows-w ..ovider-cimwin32-dl​​l_31bf3856ad364e35_6.1.7601.17514_none_2dd0f6a01caf55c6文件夾。當我嘗試重新註冊時,它返回了這樣的錯誤 - http://justpaste.it/4pi5 –