View Single Post
  #2 (permalink)  
Old 06-04-2007, 02:35 PM
alfcen's Avatar
alfcen alfcen is offline
Basic4ppc Veteran
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu
Posts: 425
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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

Code:
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 by alfcen : 11-23-2007 at 02:06 PM.
Reply With Quote