sstbrg Posted June 22, 2013 Posted June 22, 2013 (edited) I want to know how to detect devices (specifically USB devices) upon plug-in and for instance do something (MsgBox would be OK for a start). Now I did some searching here and concluded that I should do more reading on WMI. I did some reading and I understand that I need to monitor events generated by windows. One of those events might as well be a device being plugged into a USB port (which is what I need to detect). Alas I only have limited programming knowledge and really no computer science background, so stuff like "rootCIMV2" and objWMIService.ExecNotificationQuery (especially what to write as the string parameter there) got me confused a little. The topics I found here and elsewhere on the web deal with detecting drives and specifically drive letters but I need to be able to detect any USB device, such as a USB controller or a virtual serial port for instance. My resources so far: The topic about detecting drives: '?do=embed' frameborder='0' data-embedContent>> I also found a list of win32 classes on MSDN so that might be helpful as well but I'm still not sure how to implement this: http://msdn.microsoft.com/en-us/library/windows/desktop/aa389273(v=vs.85).aspx Monitoring Events (MSDN): http://msdn.microsoft.com/en-us/library/windows/desktop/aa392396(v=vs.85).aspx Hopefully you guys will be able to help me and smoothen the learning curve... Edited June 22, 2013 by sstbrg
KaFu Posted June 22, 2013 Posted June 22, 2013 I think these two posts should contain all information you're looking for: >Safely Eject a USB Drive by wraithdu > RegisterDeviceNotifications by jaberwocky6669 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
sstbrg Posted June 23, 2013 Author Posted June 23, 2013 Thanks but honestly isn't there a better and simpler way to extract info on USB devices than calling kernel32.dll and writing a thousand lines of code? I mean, just looking at the constants and the hex values which he took from god knows where rises many questions for me. If there isn't a simpler way, it's fine, I'll go for it and learn some more... but I don't want to jump into the water unless there's a simpler more elegant route.
KaFu Posted June 23, 2013 Posted June 23, 2013 (edited) Afaik this is just how it's done. kernel32 is one of the most basic, if not the most basic, Api Microsoft provides. WMI is just a wrapping framework and I think under the hood also relies on kernel32 calls. And well, everthing's there, you don't have to reinvent the wheel, just strip those parts you don't need. Edited June 23, 2013 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now