на главную | войти | регистрация | DMCA | контакты | справка | donate |      

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я


моя полка | жанры | рекомендуем | рейтинг книг | рейтинг авторов | впечатления | новое | форум | сборники | читалки | авторам | добавить




Firing WMI Events

To fire a WMI event, simply call WmiFireEvent, passing the relevant WMI event block GUID, the InstanceIndex, and any event data. WmiFireEvent makes the appropriate call to IoWmiWriteEvent.

The Wdm3 driver provides a helper function Wdm3FireEvent, shown in Listing 12.10. This takes a NULL-terminated wide string, formats it into a Wdm3Event message, and calls WmiFireEvent.

A user application must ask for events first by setting an Enable flag. This request arrives at the driver in its WmiFunctionControl optional callback routine. If the Function parameter is WmiEventControl, the new Enable setting is stored in the WMIEventEnabled flag in the device extension. WmiFunctionControl is also called to ask a driver to collect WMI data blocks that were marked as being expensive to collect.

The WMIEventEnabled flag is initially FALSE, which means that no events are generated. As I have found no way of registering for events, the Wdm3FireEvent and WmiFunctionControl functions have not been tested.


Listing 12.10 Wdm3FireEvent and WmiFunctionControl routines

void Wdm3FireEvent(IN PDEVICE_OBJECT fdo, wchar_t* Msg) {

 DebugPrint("Wdm3FireEvent: Msg %S", Msg);

 PWDM3_DEVICE_EXTENSION dx = (PWDM3_DEVICE_EXTENSION)fdo->DeviceExtension;

 if (!dx->WMIEventEnabled) return;

 // Get MsgLen in bytes

 int MsgLen = 0;

 wchar_t* Msg2 = Msg;

 while (*Msg2++!=0) MsgLen += sizeof(wchar_t);

 // Allocate event memory

 PUSHORT pData = (PUSHORT)ExAllocatePool(NonPagedPool, MsgLen+2);

 if (pData==NULL) return;

 PUSHORT pData2 = pData;

 *pData2++ = MsgLen;

 RtlMoveMemory(pData2, Msg, MsgLen);

 WmiFireEvent(fdo, (LPGUID)&WDM3_WMI_EVENT_GUID, 0, MsgLen+2, pData);

}


NTSTATUS WmiFunctionControl(IN PDEVICE_OBJECT fdo, IN PIRP Irp, IN ULONG GuidIndex, IN WMIENABLEDISABLECONTROL Function, IN BOOLEAN Enable) {

 DebugPrint("WmiFunctionControl: GuidIndex %d, Function %d, Enable %d",

  GuidIndex, Function, Enable);

 PWDM3_DEVICE_EXTENSION dx = (PWDM3_DEVICE_EXTENSION)fdo->DeviceExtension;

 if (GuidIndex==WDM3_WMI_EVENT_GUID_INDEX && Function==WmiEventControl) {

  DebugPrint("WmiFunctionControl: Event enable %d", Enable);

  dx->WMIEventEnabled = Enable;

  return WmiCompleteRequest(fdo, Irp, STATUS_SUCCESS, 0, IO_NO_INCREMENT);

 }

 return FailWMIRequest(fdo, Irp, GuidIndex);

}


ExecuteWmiMethod Handler | Writing Windows WDM Device Drivers | WMI in Action