0

[DllImport("CIMWin32.dll")] public static extern UInt32 Reset();

When I Am Calling This Method Then I Getting Exception

Unable to find an entry point named 'Reset' in DLL 'CIMWin32.dll'

Ali Bahrami
  • 5,935
  • 3
  • 34
  • 53
  • 1
    Why do you think there is a `Reset` method in this dll? – Krivitskiy Grigoriy Mar 02 '20 at 12:48
  • @KrivitskiyGrigoriy https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/reset-method-in-class-cim-controller I think it's in the docs. – Ali Bahrami Mar 02 '20 at 12:53
  • 1
    You can only call methods that have public entry points. DllImport looks at the symbol table of the dll and if the method is not an entry point than it is not in the symbol table and you can't call the method. – jdweng Mar 02 '20 at 12:54

1 Answers1

0

I'm not sure what Reset method of CIM you want to import and invoke, but this is how you can call a method in VMI. Install System.Management package via NuGet. Then you need to create an instance of ManagementClass like below:

var NamespacePath = "\\\\.\\ROOT\\cimv2";
var ClassName = "CIM_LogicalDevice";

ManagementClass managementClass = new ManagementClass(NamespacePath + ":" + ClassName);           

managementClass .InvokeMethod("Reset", null);

Of course in the code above, Reset method is not implemented. You can find your provider, class, and method in Microsoft Docs. For e.g above, I tried to call the Reset method of CIM_LogicalDevice class.

In the requirement section, you can see the namespace.

enter image description here.

If you look for the more complicated example of how to invoke WMI class methods, take a look on this example on Microsoft Docs: https://learn.microsoft.com/en-us/configmgr/develop/core/clients/programming/how-to-call-a-wmi-class-method-by-using-system.management

Ali Bahrami
  • 5,935
  • 3
  • 34
  • 53