title: Example for executing a WMI method from Windows Driver
body: <p>I am looking for an example of how to execute WMI method from Windows Driver.
  I need to call <em>TestFunction</em> from class <em>MY_WMI_CLASS</em></p>
  
  <pre><code>[WMI, dynamic: ToInstance, provider("xxx"), Locale("some"), Description("test xxx"), guid("{someguidhere}")]
  class MY_WMI_CLASS
  {
      [key, read] string InstanceName;
      [read] boolean Active;
      [WmiMethodId(1), 
            Implemented, 
            Description("Test xxx")] 
            void TestFunction([out, Description("Test f")] uint32 Data);
  };
  </code></pre>
  
  <p>MSDN says I have to call</p>
  
  <blockquote>
    <p>IoWMIQueryAllData, <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff550453(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/hardware/ff550453(v=vs.85).aspx</a></p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>IoWMIExecuteMethod, <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff550438(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/hardware/ff550438(v=vs.85).aspx</a></p>
  </blockquote>
  
  <p>functions. IoWMIExecuteMethod function has an InstanceName parameter which I don't know how to get.</p>
  
  <pre><code>NTSTATUS IoWMIExecuteMethod(
    _In_    PVOID           DataBlockObject,
    _In_    PUNICODE_STRING InstanceName,
    _In_    ULONG           MethodId,
    _In_    ULONG           InBufferSize,
    _Inout_ PULONG          OutBufferSize,
    _Inout_ PUCHAR          InOutBuffer
  );
  </code></pre>