1

WMI オブジェクト - Win32_Service からいくつかのプロパティをロードしようとする C# コードがあります。しかし、「System.Management.ManagementException: Invalid class」エラーが返されます。

私の簡略化されたコード:

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 -List | 名前を選択

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
4

2 に答える 2