WMI and Win32_DeviceChangeEvent - Wrong event type returned?

≡放荡痞女 提交于 2019-12-05 17:40:01

Well, I couldn't find the code. Tried on my old RAC account, nothing. Nothing in my old backups. Go figure. But I tried to work out how I did it, and I think this is the correct sequence (I based a lot of it on this article):

  1. Get all drive letters and cache them.
  2. Wait for the WM_DEVICECHANGE message, and start a timer with a timeout of 1 second (this is done to avoid a lot of spurious WM_DEVICECHANGE messages that start as start as soon as you insert the USB key/other device and only end when the drive is "settled").
  3. Compare the drive letters with the old cache and detect the new ones.
  4. Get device information for those.

I know there are other methods, but that proved to be the only one that would work consistently in different versions of windows, and we needed that as my client used the ActiveX control on a webpage that uploaded images from any kind of device you inserted (I think they produced some kind of printing kiosk).

Oh! Yup, I've been through that, but using the raw Windows API calls some time ago, while developing an ActiveX control that detected the insertion of any kind of media. I'll try to unearth the code from my backups and see if I can tell you how I solved it. I'll subscribe to the RSS just in case somebody gets there first.

Well,

u can try win32_logical disk class and bind it to the __Instancecreationevent. You can easily get the required info

I tried this on my system and I eventually get the right code. It just takes a while. I get a dozen or so events, and one of them is the device connect code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!