I use the following code for notification when a USB device is plugged into a USB Port, but I don’t know which GUID to use for EventCategoryData in IoRegisterPlugPlayNotification:
With GUID_CLASS_USB_DEVICE I don’t get notifications why?
MSDN:
EventCategoryData must point to a GUID specifying a device interface class. CallbackRoutine >will be called when an interface of that class is enabled or removed.
Code:
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath){ NTSTATUS status; DriverObject->DriverUnload=usblockerUnload;status=IoRegisterPlugPlayNotification( EventCategoryDeviceInterfaceChange, PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES, (PVOID)&GUID_CLASS_USB_DEVICE, DriverObject, (PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)PnpNotifyInterfaceChange, NULL, &NotificationHandle);if(!NT_SUCCESS(status)) { DbgPrint("error in IoRegisterPlugPlayNotification"); return status; }DbgPrint(" ok "); return STATUS_SUCCESS;}void usblockerUnload(IN PDRIVER_OBJECT DriverObject){ NTSTATUS status;DbgPrint(" Unload \s \r"); status=IoUnregisterPlugPlayNotification(NotificationHandle);if(!NT_SUCCESS(status)) { DbgPrint("error in IoRegisterPlugPlayNotification"); }}
NTSTATUS PnpNotifyInterfaceChange( PVOID pNotifyContext, PVOID pContext )
{
DbgPrint("USB ");
return STATUS_SUCCESS;
}
And, very important question: How can I use IoSetDeviceInterfaceState to disable an instance of a previously registered device interface class in my call back ?
i must handle Adddevice? and use INF file?
i get confuse why this callback (PnpNotifyInterfaceChange ) not called