INF problem for Plug&Play ( use IoRegisterPlugPlayNotification )
hi want to use IoRegisterPlugPlayNotification for notify when new usb get plug-in ! my code dont work (i dont get notify)
can use IoRegisterPlugPlayNotification in DriverEntry? without use Adddevice i can get notify ? i must use INF file to get notification ? why ?
what GUID i must use ? in code and INF file?
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
NTSTATUS status;
int i;
//{a5dcbf10-6530-11d2-901f-00c04fb951ed}
DriverObject->DriverUnload=usblockerUnload;
for (i=0;i<IRP_MJ_MAXIMUM_FUNCTION;i++)
DriverObject->MajorFunction[i] = Driver_PNP;
DriverObject->MajorFunction开发者_运维知识库[IRP_MJ_PNP] = Driver_PNP;
status=IoRegisterPlugPlayNotification( EventCategoryDeviceInterfaceChange,
PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
(PVOID)&GUID_CLASS_USB_DEVICE,
DriverObject,
(PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)PnpNotifyInterfaceChange,
(PVOID)DriverObject,
&NotificationHandle);
if(!NT_SUCCESS(status))
{
DbgPrint("error in IoRegisterPlugPlayNotification \n");
return status;
}
DbgPrint(" Driver Entry oK *** \n");
return STATUS_SUCCESS;
}
void usblockerUnload(IN PDRIVER_OBJECT DriverObject)
{
NTSTATUS status;
DbgPrint(" Unload \r");
status=IoUnregisterPlugPlayNotification(NotificationHandle);
if(!NT_SUCCESS(status))
{
DbgPrint("error in IoUnregisterPlugPlayNotification \n");
}
}
#pragma PAGEDCODE
NTSTATUS PnpNotifyInterfaceChange( PVOID pNotifyContext, PVOID pContext )
{
PDEVICE_INTERFACE_CHANGE_NOTIFICATION pNotifyData = (PDEVICE_INTERFACE_CHANGE_NOTIFICATION)pNotifyContext;
DbgPrint("symbolic name: %wZ\n", pNotifyData->SymbolicLinkName);
return STATUS_SUCCESS;
}
You are trying to write a NT-style driver (a.k.a. legacy driver). You don't need to install it with an .INF file; just have it installed as a service and net start yourdriver
(or set its start-up as Automatic in the service properties).
As a side note: Make sure you actually understand what you're doing. You seem to have subjects mixed up. For example, an NT-style driver does not handle IRP_MJ_PNPs -- it simply never receives them. You still can register for PnP notifications, of course: you'll receive them in a callback function, but it has nothing to do with IRP_MJ_PNP.
精彩评论