6. The device extension has these extra fields added.
WMILIB_CONTEXT WmiLibInfo; // WMI Context
BOOLEAN IdlePowerDownEnable; // Enable power down option
BOOLEAN WMIEventEnabled; // Enable WMI events
Finally,
7. The main WMI code needs to refer to the driver registry path that was passed to
// Save a copy of our RegistryPath for WMI
Wdm3RegistryPath.MaximumLength = RegistryPath->MaximumLength;
Wdm3RegistryPath.Length = 0;
Wdm3RegistryPath.Buffer = (PWSTR)ExAllocatePool(PagedPool, Wdm3RegistryPath.MaximumLength);
if (Wdm3RegistryPath.Buffer == NULL) return STATUS_INSUFFICIENT_RESOURCES;
RtlCopyUnicodeString(&Wdm3RegistryPath, RegistryPath);
The driver unload routine Wdm3Unload deletes the Wdm3RegistryPath buffer.
You must register as a WMI provider by calling
Listing 12.3 shows the
The WMILIB_CONTEXT
After calling
Listing 12.3 RegisterWmi and DeregisterWMI code
const int GUID_COUNT = 3;
WMIGUIOREGINFO Wdm3GuidList[GUID_CЩUNT] = {
{ &WDM3_WMI_GUID, 1. 0 }, // Wdm3Information
{ &GUID_POWER_DEVICE_ENABLE, 1, 0}, // MSPower_DeviceEnable
{ &WDM3_WMI_EVENT_GUID, 1, 0}, // Wdm3Event
};
const ULONG WDM3_WMI_GUID_INDEX = 0;
const ULONG GUID_POWER_DEVICE_ENABLE_INDEX = 1;
const ULONG WDM3_WMI_EVENT_GUID_INDEX = 2;
void RegisterWmi(IN PDEVICE_OBJECT fdo) {
PWDM3_DEVICE_EXTENSION dx=(PWDM3_DEVICE_EXTENSION)fdo->DeviceExtension;
dx->WmiLibInfo.GuidCount = GUID_COUNT;
dx->WmiLibInfo.GuidList = Wdm3GuidList;
dx->WmiLibInfo.QueryWmiRegInfo = QueryWmiRegInfo;
dx->WmiLibInfo.QueryWmiDataBlock = QueryWmiDataBlock;
dx->WmiLibInfo.SetWmiDataBlock = SetWmiDataBlock;
dx->WmiLibInfo.SetWmiDataItem = SetWmiDataItem;
dx->WmiLibInfo.ExecuteWmiMethod = ExecuteWmiMethod;
dx->WmiLibInfo.WmiFunctionControl = WmiFunctionControl;
NTSTATUS status = IoWMIRegistrationControl(fdo, WMIREG_ACTION_REGISTER);
DebugPrint('RegisterWmi %x', status);
}
void DeregisterWmi( IN PDEVICE_OBJECT fdo) {
IoWMIRegistrationControl(fdo, WMIREG_ACTION_DEREGISTER);
DebugPrintMsg('DeregisterWmi');
}
Table 12.1 WMILIB_CONTEXT structure
GuidCount | ULONG | Required | Count of WMI blocks |
GuidList | Required | Array with the GUIDs of the WMI blocks supported, etc. | |
QueryWmiRegInfo | Required | Provide further information about the WMIblocks you are registering | |
QueryWmiDataBlock | Callback | Required | Return a single instance or all instances of adata block |
SetWmiDataBlock | Callback | Optional | Set all data items in a single instance of adata block |
SetWmiDataItem |