How to get registry and file exclusions from UWF using WMI query in C#

前端 未结 2 1586
我寻月下人不归
我寻月下人不归 2021-01-22 22:32

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

I\'ve already tried to invoke GetExclusions methods from UWF_RegistryFilter class but of

2条回答
  •  忘了有多久
    2021-01-22 23:04

    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.

    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(@"root\standardcimv2\embedded");
            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"));
                        }
                    }
                }
            }
        }
    

    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

提交回复
热议问题