Win32_Service is missing
本文关键字:missing is Service Win32 | 更新日期: 2023-09-27 18:28:59
我有C#代码,它试图从WMI对象-Win32_Service加载一些属性。但它返回给我"System.Management.ManagementException:无效类"错误。
我的简化代码:
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-列表|选择名称
它返回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
尝试重新注册基类(当然是管理命令行…)
mofcomp %windir%'system32'wbem'cimwin32.mof
请参阅此处的"我得到一个0x80041010("无效类")错误"一节。您可能会发现一些有用的东西,特别是Scriptomatic和Wbemtest的使用。