我有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
在PowerShell中,確實'GET-WmiObject可以win32_service時|選擇名稱「工作? – nimizen
不。它不起作用。我將輸出添加到Update 1中 –
這是什麼操作系統? – nimizen