简体   繁体   English

Win32_Service丢失

[英]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 . 您可能会发现有用的东西,特别是ScriptomaticWbemtest的使用。

尝试重新注册基类(当然,是管理员命令行...)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查服务是否正在使用Win32_Service运行 - Check if a service is running with Win32_Service 调用Win32_Service UserControlService无法正常工作 - Invocation of Win32_Service UserControlService not working WPF WMI Win32_Service查询 - Wpf WMI Win32_Service Query 授予远程用户(非管理员)使用WMI和C#在命名空间cimv2中枚举Win32_Service中的服务的能力 - Granting remote user (non admin) the ability to enumerate services in Win32_Service in namespace cimv2 using WMI & C# Win32Exception: 指定的服务不作为已安装的服务存在 - Win32Exception: The specified service does not exist as an installed service 使用Win32_Product类时缺少软件条目 - Missing software entry when using Win32_Product Class Windows服务:PrintTicket提供程序无法绑定到打印机。 Win32错误:-2147467231 - Windows service: PrintTicket provider failed to bind to printer. Win32 error: -2147467231 如何使用Win32 API在与LocalSystem帐户不同的帐户下安装服务? - How can I install a service under a different account than the LocalSystem account using Win32 API? Win32异常 - Win32 Exception “作为Windows服务运行时,”Win32Exception没有足够的存储可用于处理此命令“错误 - “Win32Exception Not enough storage is available to process this command” error when run as a windows service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM