This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Check if USB device is connected

Hi,

 

I would like to monitor if a certain USB device or any other device showin in the device manager is still connected / available.

Is this somehow possible?

  • sorry that it took so long for me to respond but i wanted to verify that it works....

    works like a charm for me!

    Thanks a lot!

  • erm...

    If anyone is interested in how to check for the presence of a specific USB device just give me a shout and I will upload it to the community.

    EDIT:

    Well, I'll just share the interesting part here... (You will need to embed this in a custom vbscript monitor)

    There are two script arguments you need to pass on, the first will be ${IP} and the second one will be a string that needs to appear in one of the USB devices on that machine, make sure you make it something that is unique to the USB device you want to find! If the string is found in any of the USB Devices of the machine, it will return a Statistic of '1', if it is not found it will return a Statistic of '0'. Hope someone might find it useful :P

    strComputer = WScript.Arguments(0)
    strUSBDevice = WScript.Arguments(1)
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colDevices = objWMIService.ExecQuery _
        ("Select * From Win32_USBControllerDevice")
    For Each objDevice in colDevices
        strDeviceName = objDevice.Dependent
        strQuotes = Chr(34)
        strDeviceName = Replace(strDeviceName, strQuotes, "")
        arrDeviceNames = Split(strDeviceName, "=")
        strDeviceName = arrDeviceNames(1)
        Set colUSBDevices = objWMIService.ExecQuery _
            ("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'")
        For Each objUSBDevice in colUSBDevices
            If InStr(objUSBDevice.Description,strUSBDevice) > 0 THEN
        WScript.Echo "Statistic: 1"
        WScript.Quit( SUCCESS )   
            End If
        Next   
    Next
    WScript.Echo "Message: USB Device not found!"
    WScript.Echo "Statistic: 0"
    WScript.Quit( FAILED )

  • Stumbled across this when trying to do the same. I have done this by running the below command in powershell and make note of the 'caption' of the required USB

    gwmi Win32_USBControllerDevice | %{ [wmi]($_.Dependent)} |Sort Description,DeviceID | ft Description,Caption -auto

    Then in SAM create a new template, create a powershell component and enter the below, changing <USB device> to the caption we found above.

    If ((Get-WmiObject Win32_PnPEntity -filter "name='<USB Device>'" -ComputerName '${IP}' -Credential '${CREDENTIAL}').status = "ok") {

    Write-Host "Statistic:  0"

    exit 0;

    }

    Write-Host "Statistic:  1"

    exit  1;

    I have also uploaded my template to thwack, it is called 'USB License Dongle'

  • Hi There,

    I need to check if there is USB dongle connected to a machine and preferable to get as much details of it.

    I was wondering if you managed to retrieve this information using vbs?

    Thanks,

    Joao