网上找了些资料,处理WM_DEVICECHANGE消息就能获知U盘,插上拔下
但是Service程序里面怎么处理窗口消息?

解决方案 »

  1.   

    See the documentation for RegisterDeviceNotification : You can pass a service status handle instead of a window handle.From MSDN :"Services can use the RegisterDeviceNotification function to register to receive device notifications. If a service specifies a window handle in the hRecipient parameter, the notifications are sent to the window procedure. If hRecipient is a service status handle, 
    SERVICE_CONTROL_DEVICEEVENT notifications are sent to the service control handler. For more information about the service control handler, see HandlerEx."
      

  2.   

    也可以写个usb过滤驱动和应用程序交互