如何在 C# 中使用 WMI 查询从 UWF 获取注册表和文件排除项

How to get registry and file exclusions from UWF using WMI query in C#(如何在 C# 中使用 WMI 查询从 UWF 获取注册表和文件排除项)
本文介绍了如何在 C# 中使用 WMI 查询从 UWF 获取注册表和文件排除项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 WMI 从 UWF 获取所有注册表排除和文件排除.

I want to get all registry exclusion and file exclusion from UWF, using the WMI.

我已经尝试从 UWF_RegistryFilter 类调用 GetExclusions 方法,但没有成功.

I've already tried to invoke GetExclusions methods from UWF_RegistryFilter class but of no luck.

我期待一个有效的示例代码,提前感谢您的帮助!

I am looking forward to a working sample code, thanks in advance for any help!

推荐答案

难点是从方法结果中读取出参数.Microsoft 网站 很难猜测如何使用 ManagementBaseObject 来读取输出参数.

The difficult part is to read the out parameters from the method result. There is no appropriate documentation available on Microsoft website and it's difficult to guess how ManagementBaseObject can be utilized for reading the out parameters.

为了找到解决方案,我尝试根据其他有据可查的 wmi 示例了解 WMI 如何利用 out 参数.请使用下面的C#代码,希望对您有所帮助:

In order to reach to a solution, I tried to develop an understanding of how WMI makes use of out parameters based on other well-documented wmi samples. Please use the C# code below, I hope it helps:

public static void GetRegistryExclusions()
    {

        ManagementScope scope = new ManagementScope(@"rootstandardcimv2embedded");
        using (ManagementClass mc = new ManagementClass(scope.Path.Path, "UWF_RegistryFilter",
        null))
        {
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                ManagementBaseObject[] result = (ManagementBaseObject[])mo.InvokeMethod("GetExclusions", null, null).Properties["ExcludedKeys"].Value;

                if (result != null)
                {
                    foreach (var r in result)
                    {
                        Console.WriteLine(r.GetPropertyValue("RegistryKey"));
                    }
                }
            }
        }
    }

注意/请求请求具有 1500 声望的人创建和链接以下标签,以便像我这样的人在 stackoverflow 上请求解决方案/回答问题变得更加容易.

Note/Request Request someone with 1500 reputation to create and link following tags so that it becomes easier for people like me to request solutions/answer questions on stackoverflow.

  1. UWF
  2. UWFMGR

这篇关于如何在 C# 中使用 WMI 查询从 UWF 获取注册表和文件排除项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)