2016-05-09 23 views
0

Ich bin auf der Suche nach einem Beispiel für die WMI-Methode von Windows-Treiber ausführen. I Testfunction von Klasse MY_WMI_CLASSBeispiel zum Ausführen einer WMI-Methode von Windows-Treiber

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

MSDN anrufen müssen, sagt ich

IoWMIQueryAllData, https://msdn.microsoft.com/en-us/library/windows/hardware/ff550453(v=vs.85).aspx

und

verlangen

IoWMIExecuteMethod, https://msdn.microsoft.com/en-us/library/windows/hardware/ff550438(v=vs.85).aspx

Funktionen. Die IoWMIExecuteMethod-Funktion hat einen InstanceName-Parameter, den ich nicht kenne.

NTSTATUS IoWMIExecuteMethod(
    _In_ PVOID   DataBlockObject, 
    _In_ PUNICODE_STRING InstanceName, 
    _In_ ULONG   MethodId, 
    _In_ ULONG   InBufferSize, 
    _Inout_ PULONG   OutBufferSize, 
    _Inout_ PUCHAR   InOutBuffer 
); 
+0

Was möchten Sie erreichen? Können Sie den MSDN-Link teilen, damit wir eine bessere Lösung anbieten können? –

+0

hat weitere Informationen hinzugefügt – ilia

Antwort

0

Eine Antwort auf meine eigene Frage gefunden.

PVOID  wmiObject = NULL; 
    ULONG  allocSize = 100; 
    UCHAR  pBuffer[100] = ; 

    //Open block 
    rc = IoWMIOpenBlock(&guid, WMIGUID_EXECUTE, &wmiObject); 

    //get instance name 
    rc = IoWMIQueryAllData(wmiObject, &allocSize, pBuffer); 


    WNODE_ALL_DATA *pWNode = (WNODE_ALL_DATA*)pBuffer; 
    ULONG offset = *((PULONG)(pBuffer + pWNode->OffsetInstanceNameOffsets)); 
    PWCHAR str = (PWCHAR)(pBuffer + offset + 2); 

    UNICODE_STRING uniInstanceName = { 0 }; 
    RtlInitUnicodeString(&uniInstanceName, str); 

    UINT8 data[100]; 
    size = 100; 

    //execute a method 
    rc = IoWMIExecuteMethod(wmiObject, &uniInstanceName, 1, 0, &size, data);