[英]Win32_Service is missing
I have C# code that tries to load some property from WMI object - Win32_Service. 我有C#代码,试图从WMI对象-Win32_Service加载某些属性。 But it returns to me 'System.Management.ManagementException: Invalid class ' error.
但是它返回给我“ System.Management.ManagementException:无效的类”错误。
My simplified code: 我的简化代码:
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));
}
Also I've tried to load list of WMI objects by PowerShell command - 我也尝试通过PowerShell命令加载WMI对象列表-
Get-WmiObject -List | Get-WmiObject-列表| Select Name
选择名字
It returns 91 objects, but it misses Win32_Service object. 它返回91个对象,但缺少Win32_Service对象。 I googled how to reinstall it, but didn't found it.
我用谷歌搜索了如何重新安装它,但是没有找到它。 Is there a way to reinstall it somehow?
有办法以某种方式重新安装它吗?
Thank you 谢谢
Update 1: Output for Powershell command: 更新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
See the section "I'm getting an 0x80041010 (“Invalid Class”) error" here . 请参阅此处的 “我收到0x80041010(“无效类”)错误”部分。 You might find something useful, in particular the use of Scriptomatic and Wbemtest .
您可能会发现有用的东西,特别是Scriptomatic和Wbemtest的使用。
尝试重新注册基类(当然,是管理员命令行...)
mofcomp %windir%\system32\wbem\cimwin32.mof
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.