2013-08-23 22 views
0

WMI 개체 (Win32_Service)에서 일부 속성을로드하려고하는 C# 코드가 있습니다. 그러나 그것은 나에게 '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 오브젝트의 목록을로드하려고했습니다 -

가져-WmiObject를 -List | 이름 선택

91 개의 개체를 반환하지만 Win32_Service 개체가 누락되었습니다. 나는 그것을 다시 설치하는 방법을 봤지만 찾지 못했습니다. 어떻게 든 다시 설치하는 방법이 있습니까? PowerShell 명령에 대한 출력 :

업데이트 1 감사

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

(... 물론, 관리 명령 행) 기본 클래스를 재 등록하십시오 | 이름을 선택하시오? – nimizen

+0

nope. 작동하지 않습니다. 업데이트 1에 출력을 추가했습니다. –

+0

어떤 OS입니까? – nimizen

답변

1

은 "(잘못된 클래스") 오류 "here 내가 0x80041010 받고 있어요"절을 참조하십시오. 특히 ScriptomaticWbemtest을 사용하면 유용 할 수 있습니다.

+0

wbemtest를 시도했습니다. 그러나 Connect를 클릭하면 "Number : 0x80040154 Facility : Interface 설명 : 클래스가 등록되지 않았습니다." –

0

`의 Win32_Service-WmiObject를 얻기 않습니다 PowerShell에서

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

cimwin32.mof를 찾은 유일한 곳은 C : \ Windows \ winsxs \ amd64_microsoft-windows-w입니다. ..ovider-cimwin32-dll_31bf3856ad364e35_6.1.7601.17514_none_2dd0f6a01caf55c6 폴더. 등록을 다시 시도 할 때 오류가 발생했습니다 - http://justpaste.it/4pi5 –