Fronter Posted June 16, 2009 Share Posted June 16, 2009 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? Link to comment Share on other sites More sharing options...
BrettF Posted June 16, 2009 Share Posted June 16, 2009 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 Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Fronter Posted June 16, 2009 Author Share Posted June 16, 2009 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 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 More sharing options...
James Posted June 16, 2009 Share Posted June 16, 2009 I know it's a cheap trick, but why not use DriveGetType and poll the amount of times "REMOVABLE" is counted? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
martin Posted June 16, 2009 Share Posted June 16, 2009 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 More sharing options...
Fronter Posted June 16, 2009 Author Share Posted June 16, 2009 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 More sharing options...
martin Posted June 16, 2009 Share Posted June 16, 2009 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 More sharing options...
Valuater Posted June 16, 2009 Share Posted June 16, 2009 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) Link to comment Share on other sites More sharing options...
martin Posted June 16, 2009 Share Posted June 16, 2009 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 More sharing options...
martin Posted June 16, 2009 Share Posted June 16, 2009 (edited) 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 June 16, 2009 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 More sharing options...
BrettF Posted June 17, 2009 Share Posted June 17, 2009 http://www.microsoft.com/technet/scriptcen...05/hey0315.mspxAnd you can do heaps more with it too... expandcollapse popup$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 NextCheers,Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
tom35i Posted November 16, 2009 Share Posted November 16, 2009 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 More sharing options...
Bert Posted November 16, 2009 Share Posted November 16, 2009 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! The Vollatran project  My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
mesale0077 Posted November 16, 2009 Share Posted November 16, 2009 hi line 4 error $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colDevices = $objWMIService.ExecQuery ("Select * From Win32_USBControllerDevice") error "object" why? Link to comment Share on other sites More sharing options...
Fronter Posted May 11, 2011 Author Share Posted May 11, 2011 Thanks the help! Link to comment Share on other sites More sharing options...
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