简体   繁体   中英

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://docs.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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM