Jump to content
Sign in to follow this  
Belini

Detect USB devices connected.

Recommended Posts

Belini

I need to know which USB devices are plugged into the PC and save it in a file. Ini, which command does this?

Share this post


Link to post
Share on other sites
mrflibblehat

Something like this.

$vFile = FileOpen("usb.txt", 2)

Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")

    $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_USBHub')
    If IsObj($vObjItems) Then
        For $vObjItem In $vObjItems
                FileWriteLine($vFile, $vObjItem.Description & @CRLF)
                FileWriteLine($vFile, $vObjItem.DeviceID & @CRLF & @CRLF)
        Next
    EndIf

FileClose($vFile)

ShellExecute("usb.txt")

or if your specifically looking for USB Drives. maybe the below.

$vFile = FileOpen("usb.txt", 2)

Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")

    $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_DiskDrive')
    If IsObj($vObjItems) Then
        For $vObjItem In $vObjItems
            If StringInStr($vObjItem.Caption, "USB") Then
                FileWriteLine($vFile, $vObjItem.Caption & @CRLF)
                FileWriteLine($vFile, $vObjItem.DeviceID & @CRLF & @CRLF)
            EndIf
        Next
    EndIf

FileClose($vFile)

ShellExecute("usb.txt")
Edited by mrflibblehat
  • Like 1

[font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]

Share this post


Link to post
Share on other sites
Belini

I do not want to find drivers but human interface devices like keyboard, mouse and USB joystick.

Edited by Belini

Share this post


Link to post
Share on other sites
mrflibblehat

Have a look at >this post.

Or have a look at the below.

$vFile = FileOpen("usb.txt", 2)

Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")

    $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_PnPEntity')
    If IsObj($vObjItems) Then
        For $vObjItem In $vObjItems
            If StringInStr($vObjItem.PNPDeviceID, "HID\") Then
                FileWriteLine($vFile, $vObjItem.Name & @CRLF)
                FileWriteLine($vFile, $vObjItem.DeviceID & @CRLF & @CRLF)
            EndIf
        Next
    EndIf

FileClose($vFile)

ShellExecute("usb.txt")
Edited by mrflibblehat

[font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]

Share this post


Link to post
Share on other sites
Belini

@mrflibblehat i tried everything that was posted there and could not identify the devices connected human interface on the PC, and the code you posted does not report that the device is connected.

Edited: This program shows http://www.nirsoft.net/utils/usb_devices_view.html more with Autoit not know how to do.

Edited by Belini

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  

×