Jump to content
Sign in to follow this  

Detecting devices using AutoIt

Recommended Posts

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 by sstbrg

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

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 by KaFu

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...