Jump to content

Free USB port counter


Recommended Posts

Welcome.

It will probably have to be done with WMI.

Have you searched the forum? Remember to try the computer info scripts and the like too.

Cheers,

Brett

:D

Link to comment
Share on other sites

Welcome.

It will probably have to be done with WMI.

Have you searched the forum? Remember to try the computer info scripts and the like too.

Cheers,

Brett

:D

Hello.

Yes, of course I had searched for it. I haven't found instructions about it. I neither can't count the number of USB ports, nor the connected active devices.

Link to comment
Share on other sites

I woulld like to write a script, which can count the free USB ports on a computer. How can i start it? What kind of parameters have to investigate?

As far as I can see you can't tell how many USB ports there are on a computer using device manager let alone the number of free ports, so I would be surpised if you can find out with a program. Since more than one device can be plugged into a port it makes it even more difficult to know what a free port is.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

As far as I can see you can't tell how many USB ports there are on a computer using device manager let alone the number of free ports, so I would be surpised if you can find out with a program. Since more than one device can be plugged into a port it makes it even more difficult to know what a free port is.

Ok. Let's approach the problem other side. Can I get that information, how many USB port is used, and what kind of device (for example: Scanner, Printer, Card reader, keyboard...) attached that USB port?

Link to comment
Share on other sites

Ok. Let's approach the problem other side. Can I get that information, how many USB port is used, and what kind of device (for example: Scanner, Printer, Card reader, keyboard...) attached that USB port?

That sounds possible. A quick google showed lots of links and this one was first.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Kinda interesting....

$strComputer = "."

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colDevices = $objWMIService.ExecQuery ("Select * From Win32_USBControllerDevice")

For $objDevice in $colDevices
    $strDeviceName = $objDevice.Dependent
    ;ConsoleWrite("!>" & $strDeviceName & @CRLF)
    $strQuotes = Chr(34)
    $strDeviceName = StringReplace($strDeviceName, $strQuotes, "")
    $arrDeviceNames = StringSplit($strDeviceName, "=")
    $strDeviceName = $arrDeviceNames[2]
    $colUSBDevices = $objWMIService.ExecQuery ("Select * From Win32_PnPEntity Where DeviceID = '" & $strDeviceName & "'")
    For $objUSBDevice in $colUSBDevices
        ;Wscript.Echo 
        ConsoleWrite("-->" & $objUSBDevice.Description & @CRLF)
    Next    
Next

8)

NEWHeader1.png

Link to comment
Share on other sites

Kinda interesting....

$strComputer = "."

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colDevices = $objWMIService.ExecQuery ("Select * From Win32_USBControllerDevice")

For $objDevice in $colDevices
    $strDeviceName = $objDevice.Dependent
    ;ConsoleWrite("!>" & $strDeviceName & @CRLF)
    $strQuotes = Chr(34)
    $strDeviceName = StringReplace($strDeviceName, $strQuotes, "")
    $arrDeviceNames = StringSplit($strDeviceName, "=")
    $strDeviceName = $arrDeviceNames[2]
    $colUSBDevices = $objWMIService.ExecQuery ("Select * From Win32_PnPEntity Where DeviceID = '" & $strDeviceName & "'")
    For $objUSBDevice in $colUSBDevices
        ;Wscript.Echo 
        ConsoleWrite("-->" & $objUSBDevice.Description & @CRLF)
    Next    
Next

8)

Yes, thanks for the conversion Valuater. And it seems to tell you how many USB ports there are and which ones are free as well as what is connected. Amazing!

mgrefusbports1

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

No, it doesn't. It just lists a bunch of crap that looks like it was pulled from the Device Manager. This is what I got from running the script.

Can you tell me how many USB ports I have, and how many are free? How many devices are connected, and what they are?

Answer:

I have 14 total USB ports, with 11 free ports. Connected Devices are my mouse, keyboard, and game controller.

I don't think you can get that information from Device Manager and I don't agree that it a bunch of crap.

On the PC I tried it on the number of USB Root hubs corresponded to the number of USB ports on the PC, the USB Root Hubs with nothing after them had no devices plugged in and the one USB Root Hub which was followed by a list had devices plugged in. So on that comparison your PC has at least 3 USB ports with nothing in them which from your answer is still a valid and possibly useful result. Admittedly it doesn't tell you the total number of available ports but as I said in an earlier post, since you can plug more than one device into a port that may not be possible.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

http://www.microsoft.com/technet/scriptcen...05/hey0315.mspx

And you can do heaps more with it too...

$strComputer = "."

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colDevices = $objWMIService.ExecQuery("Select * From Win32_USBControllerDevice")

For $objDevice In $colDevices
    ConsoleWrite("-->" & $objDevice.Dependent & @CRLF)
    ConsoleWrite(@TAB & "- Access State = " & $objDevice.AccessState & @CRLF)
    ConsoleWrite(@TAB & "- Antecedent = " & $objDevice.Antecedent & @CRLF)
    ConsoleWrite(@TAB & "- Negotiated Data Width = " & $objDevice.NegotiatedDataWidth & @CRLF)
    ConsoleWrite(@TAB & "- Negotiated Speed = " & $objDevice.NegotiatedSpeed & @CRLF)
    ConsoleWrite(@TAB & "- # Hard resets = " & $objDevice.NumberOfHardResets & @CRLF)
    ConsoleWrite(@TAB & "- # Soft Resets = " & $objDevice.NumberOfSoftResets & @CRLF)

    $strDeviceName = $objDevice.Dependent
;ConsoleWrite("!>" & $strDeviceName & @CRLF)
    $strQuotes = Chr(34)
    $strDeviceName = StringReplace($strDeviceName, $strQuotes, "")
    $arrDeviceNames = StringSplit($strDeviceName, "=")
    $strDeviceName = $arrDeviceNames[2]
    $colUSBDevices = $objWMIService.ExecQuery("Select * From Win32_PnPEntity Where DeviceID = '" & $strDeviceName & "'")
    For $objUSBDevice In $colUSBDevices
        ConsoleWrite(@TAB & "--> Device Information for " & $objUSBDevice.Description & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Availability = " & $objUSBDevice.Availability & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Caption = " & $objUSBDevice.Caption & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Class GUID = " & $objUSBDevice.ClassGuid & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Congfig MGR Error Code = " & $objUSBDevice.ConfigManagerErrorCode & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Config MGR User Congfig = " & $objUSBDevice.ConfigManagerUserConfig & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Creation Class Name = " & $objUSBDevice.CreationClassName & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Device ID = " & $objUSBDevice.DeviceID & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Error Cleared = " & $objUSBDevice.ErrorCleared & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Error Description = " & $objUSBDevice.ErrorDescription & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Install Date = " & $objUSBDevice.InstallDate & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Last Error Code = " & $objUSBDevice.LastErrorCode & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Manufacturer = " & $objUSBDevice.Manufacturer & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Name = " & $objUSBDevice.Name & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Plug and Play DeviceID = " & $objUSBDevice.PNPDeviceID & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Power Management Capablitites = " & $objUSBDevice.PowerManagementCapabilities & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Power Manegement Supported = " & $objUSBDevice.PowerManagementSupported & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Service = " & $objUSBDevice.Service & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Status = " & $objUSBDevice.Status & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- Status Info = " & $objUSBDevice.StatusInfo & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- System Creation Class Name = " & $objUSBDevice.SystemCreationClassName & @CRLF)
        ConsoleWrite(@TAB & @TAB & "- System Name = " & $objUSBDevice.SystemName & @CRLF)
    Next
Next

Cheers,

Brett

Link to comment
Share on other sites

  • 4 months later...

hey, i aint that great at this but how can i get this code to just display the amount of usb ports on a machine?

cheers

YEA BOIhttp://www.myspace.com/comeoutfiringhttp://www.last.fm/music/comeoutfiringhttp://www.facebook.com/pages/comeoutfiring/75676261698http://www.reverbnation.com/comeoutfiringhttp://www.purevolume.com/comeoutfiringhttp://www.twitter.com/comeoutfiringhttp://www.youtube.com/comeoutfiring

Link to comment
Share on other sites

Kinda interesting....

$strComputer = "."

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colDevices = $objWMIService.ExecQuery ("Select * From Win32_USBControllerDevice")

For $objDevice in $colDevices
    $strDeviceName = $objDevice.Dependent
    ;ConsoleWrite("!>" & $strDeviceName & @CRLF)
    $strQuotes = Chr(34)
    $strDeviceName = StringReplace($strDeviceName, $strQuotes, "")
    $arrDeviceNames = StringSplit($strDeviceName, "=")
    $strDeviceName = $arrDeviceNames[2]
    $colUSBDevices = $objWMIService.ExecQuery ("Select * From Win32_PnPEntity Where DeviceID = '" & $strDeviceName & "'")
    For $objUSBDevice in $colUSBDevices
        ;Wscript.Echo 
        ConsoleWrite("-->" & $objUSBDevice.Description & @CRLF)
    Next    
Next

8)

Nice work!
Link to comment
Share on other sites

  • 1 year later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...