3

I am writing a program that needs to enable UWF. Unfortunately, I have no experience with the WMI interface and the UWF documentation has no C# or .NET examples.

When I enable UWF, I get an exception: 'Invalid method Parameters(s)'. But, according to the documentation - https://learn.microsoft.com/en-us/windows-hardware/customize/enterprise/uwf-filter - Enable does not have input parameters. Passing through null doesn't work neither:

var scope = new ManagementScope(@"root\standardcimv2\embedded");
var uwfClass = new ManagementClass(scope.Path.Path, "UWF_Filter", null);
var inputParameters = uwfClass.GetMethodParameters("Enable");
var result = uwfClass.InvokeMethod("Enable", inputParameters, null);
clamp
  • 33,000
  • 75
  • 203
  • 299
Zavulon
  • 121
  • 8

1 Answers1

3

Ok, after a lot of headache, I finally know why it didn't work. The ManagementClass only represents a class, not the object (instance). To make it work, I need to invoke the method on the instance:

var instances = uwfClass.GetInstances();

foreach (ManagementObject instance in instances)
{
    var result = instance.InvokeMethod("Enable", null);
    break; //There should only be one instance, but to be sure, exit after first instance
}

It might be logical, but not very obvious if you are not used to WMI.

Zavulon
  • 121
  • 8
  • I know my answer is a bit late ;-): I created a small C# application some time ago (open source under MIT license), in which I enable and disable the UW filter via CIM (WMI), among other things. Maybe it helps someone... – creg Nov 27 '21 at 14:43