Reading com ports information from the registry

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Erel
Thanks so much for your fantastic snippet!
It supports my therory about scanning GPS devices in a more elegant way.
I have modified the code to allow recognition of PnpId of external devices, such as CF GPS cards and further to show the Key entry if no FriendlyName available.
Cheers
Robert

B4X:
Sub Globals
  Dim subKeys(0),values(0)
  Dim id, fn
End Sub

Sub App_Start
  Form1.Show
  Reg.New1
  Reg.RootKey(Reg.rtLocalMachine)
  If Not(cPPC) Then
    MsgBox("This application is not supported on the desktop.")
    AppClose
  End If
  al1.Clear  'for repeated queries
  subKeys() = Reg.GetSubKeyNames("Drivers\Active") 'Gets the list of active drivers.
  For i = 0 To ArrayLen(SubKeys())-1
    values() = Reg.GetValueNames("Drivers\Active\" & subKeys(i))
    For i2 = 0 To ArrayLen(values())-1
      If values(i2) = "Name" Then 'Checks if Name value exists.
        name = Reg.GetValue("Drivers\Active\" & subKeys(i),"Name")
        If SubString(name,0,3) = "COM" Then  'Checks if the driver name starts with COM.
          key = Reg.GetValue("Drivers\Active\" & subKeys(i),"Key")
          fn = reg.GetValue(key,"FriendlyName")
          id = Reg.GetValue("Drivers\Active\" & subKeys(i),"PnpId")
          If fn = "" Then fn = key           'Use Key if no FriendlyName available
          If StrLength(id) > 0 Then fn = ""  'Prefer PnpId over Key'
          al1.Add(name & " " & fn & id)      'Gets the FriendlyName value and PnpId, if available.
        End If
        Exit
      End If
    Next
  Next      
  al1.Sort(cCaseUnsensitive) 'Sorts the values.
  ListBox1.Clear    'for repeated queries
  For i = 0 To al1.Count-1
    ListBox1.Add(al1.Item(i)) 'Adds the values to the ListBox.
  Next
End Sub
 
Last edited:

Angor

Member
USB port scanner

Hi, what about USB scanner ?
I want to use iPod as external data storage, but it not work property without additional drivers. And I decided that I should write drivers myself, but I don't now how to scan USB ports.
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Angor,

On an iPAQ (PPC 2003SE), the above routine will reveal

COM9: Serial on USB

Maybe it helps knowing to which port USB is tied.

Cheers
Robert
 
Top