Search code examples
wmic#-2.0uwfuwfmgr

Enable UWF via WMI


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);

Solution

  • 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.