home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Computer_I53337252002.psc / functions.bas next >
Encoding:
BASIC Source File  |  2002-02-06  |  30.0 KB  |  862 lines

  1. Attribute VB_Name = "functions"
  2. Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" _
  3.     (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
  4.     ByVal samDesired As Long, phkResult As Long) As Long
  5.  
  6. Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
  7.  
  8. Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" _
  9.     (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
  10.     lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, _
  11.     lpcbClass As Long, lpftLastWriteTime As Any) As Long
  12.  
  13. Declare Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" _
  14.     (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
  15.     
  16. Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
  17.     (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
  18.     lpType As Long, lpData As Any, lpcbData As Long) As Long
  19.  
  20. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
  21.     (ByVal lpBuffer As String, nSize As Long) As Long
  22.  
  23. Private Declare Function NetUserEnum Lib "Netapi32" (servername As Byte, _
  24.     ByVal level As Long, ByVal filter As Long, buff As Long, ByVal buffsize As Long, _
  25.     entriesread As Long, totalentries As Long, resumehandle As Long) As Long
  26.  
  27. Private Declare Function NetApiBufferFree Lib "Netapi32" (ByVal Buffer As Long) As Long
  28.  
  29. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (xDest As Any, _
  30.     xSource As Any, ByVal nBytes As Long)
  31.  
  32. Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
  33.  
  34.  
  35.  
  36. Private Const MAX_COMPUTERNAME_LENGTH As Long = 31
  37. Private Const FILTER_WORKSTATION_TRUST_ACCOUNT = &H10
  38.  
  39. Public Const HKEY_PERFORMANCE_DATA = &H80000004
  40. Public Const HKEY_DYN_DATA = &H80000006
  41. Public Const HKEY_CURRENT_CONFIG = &H80000005
  42. Public Const HKEY_CLASSES_ROOT = &H80000000
  43. Public Const HKEY_CURRENT_USER = &H80000001
  44. Public Const HKEY_LOCAL_MACHINE = &H80000002
  45. Public Const HKEY_USERS = &H80000003
  46.  
  47. Public Const KEY_ALL_ACCESS = &H3F
  48. Public Const REG_OPTION_NON_VOLATILE = 0&
  49. Public Const REG_CREATED_NEW_KEY = &H1
  50. Public Const REG_OPENED_EXISTING_KEY = &H2
  51. Public Const ERROR_SUCCESS = 0&
  52. Public Const REG_SZ = (1)
  53.  
  54.  
  55. Public Const SYNCHRONIZE = &H100000
  56. Public Const STANDARD_RIGHTS_ALL = &H1F0000
  57. Public Const KEY_QUERY_VALUE = &H1
  58. Public Const KEY_SET_VALUE = &H2
  59. Public Const KEY_CREATE_LINK = &H20
  60. Public Const KEY_CREATE_SUB_KEY = &H4
  61. Public Const KEY_ENUMERATE_SUB_KEYS = &H8
  62. Public Const KEY_EVENT = &H1
  63. Public Const KEY_NOTIFY = &H10
  64. Public Const READ_CONTROL = &H20000
  65. Public Const STANDARD_RIGHTS_READ = (READ_CONTROL)
  66. Public Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
  67.  
  68. Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
  69. Public Const KEY_EXECUTE = (KEY_READ)
  70. Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
  71. Public Const REG_BINARY = 3
  72.  
  73. Public Const REG_DWORD = 4
  74. Public Const REG_DWORD_BIG_ENDIAN = 5
  75. Public Const REG_DWORD_LITTLE_ENDIAN = 4
  76. Public Const REG_EXPAND_SZ = 2
  77. Public Const REG_FULL_RESOURCE_DESCRIPTOR = 9
  78. Public Const REG_LINK = 6
  79. Public Const REG_MULTI_SZ = 7
  80. Public Const REG_NONE = 0
  81.  
  82. Public Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
  83. Public Const REG_NOTIFY_CHANGE_LAST_SET = &H4
  84. Public Const REG_NOTIFY_CHANGE_NAME = &H1
  85. Public Const REG_NOTIFY_CHANGE_SECURITY = &H8
  86. Public Const REG_OPTION_BACKUP_RESTORE = 4
  87. Public Const REG_OPTION_CREATE_LINK = 2
  88.  
  89. Public Const REG_OPTION_RESERVED = 0
  90. Public Const REG_OPTION_VOLATILE = 1
  91. Public Const REG_LEGAL_CHANGE_FILTER = (REG_NOTIFY_CHANGE_NAME Or REG_NOTIFY_CHANGE_ATTRIBUTES Or REG_NOTIFY_CHANGE_LAST_SET Or REG_NOTIFY_CHANGE_SECURITY)
  92. Public Const REG_LEGAL_OPTION = (REG_OPTION_RESERVED Or REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE)
  93.  
  94. Type SECURITY_ATTRIBUTES
  95.     nLength As Long
  96.     lpSecurityDescriptor As Long
  97.     bInheritHandle As Long
  98. End Type
  99.  
  100. Type DevTypes
  101.     Class As String
  102.     Name As String
  103. End Type
  104.  
  105. Type DevProps
  106.     PropDesc As String
  107.     PropVal As String
  108. End Type
  109.  
  110. Type CPU
  111.     ProcessorNameString As String
  112.     VendorIdentifier As String
  113.     Identifier As String
  114.     MHz As String
  115. End Type
  116.  
  117.  
  118. Type ComputerInfo
  119.     ProductName As String
  120.     CurrentVersion As String
  121.     CurrentBuildNumber As String
  122.     CSDVersion As String
  123.     ProductID As String
  124.     RegisteredOwner As String
  125.     RegisteredOrganization As String
  126.     SystemIdentifier As String
  127.     SystemBiosDate As String
  128.     SystemBiosVersion As String
  129.     VideoBiosDate As String
  130.     VideoBiosVersion As String
  131. End Type
  132.     
  133.     
  134. Type DeviceInfo 'hold device information
  135.     DevProps() As DevProps
  136. End Type
  137.  
  138. Type DriverInfo 'hold driver information
  139.     DevProps() As DevProps
  140. End Type
  141.  
  142. Type ExtraInfo 'hold extra information
  143.     DevProps() As DevProps
  144. End Type
  145.  
  146. Private DeviceKey As String 'registry key that holds device information
  147.  
  148. Private DriverKey As String 'registry key that holds driver information
  149.  
  150. Private DriverPath As String 'current device driver path
  151.  
  152. Public DevTypes() As DevTypes 'device type information
  153.  
  154. Public ExtraInfo() As ExtraInfo, DeviceInfo() As DeviceInfo, DriverInfo() As DriverInfo
  155.  
  156. Public CI As ComputerInfo, CPU As CPU
  157.  
  158. Public ComputerName As String
  159.  
  160. Private NumExtDevProps As Long, NumDevProps As Long, NumDrvProps As Long
  161.  
  162. Private Count(100) As Long 'counter for keeping track of location in registry
  163.  
  164. Private NumDevices As Long  'the number of matching devices found
  165.  
  166. Private NumExtraInfo As Long 'extra info data count
  167.  
  168. Private WinVersion As String 'version of windows in fixed format
  169.  
  170. Private NumDevTypes As Long 'number of device types found
  171.  
  172. Private lhRemoteRegistry As Long
  173.  
  174. Function ReadRemoteReg(ByVal KeyRoot As Long, _
  175.     ByVal sRegPath As String, ByVal sValueName) As String
  176.     Dim hKey As Long
  177.     Dim KeyValType As Long
  178.     Dim KeyValSize As Long
  179.     Dim KeyVal As String
  180.     Dim tmpVal As String
  181.     Dim res As Long
  182.     Dim i As Integer
  183.     Dim iChar As Integer
  184.     Dim sChar, sWorkStr As String
  185.     Dim bUseZero As Boolean
  186.     Dim lReturnCode, lHive
  187.     
  188.   
  189.     'open the specified key
  190.     res = RegOpenKeyEx(lhRemoteRegistry, sRegPath, 0, KEY_READ, hKey)
  191.     
  192.     'check for errors
  193.     If res <> 0 Then GoTo Errore
  194.     
  195.     'fill buffer
  196.     tmpVal = String(1024, 0)
  197.     
  198.     KeyValSize = 1024
  199.     
  200.     'get the value of the specified key
  201.     res = RegQueryValueEx(hKey, sValueName, 0, KeyValType, ByVal tmpVal, KeyValSize)
  202.     
  203.     'check for errors
  204.     If res <> 0 Then GoTo Errore
  205.     
  206.     'properly format data received
  207.     Select Case KeyValType
  208.     Case REG_SZ
  209.         'remove trailing chr(0)
  210.         tmpVal = Left(tmpVal, InStr(1, tmpVal, Chr(0), vbTextCompare) - 1)
  211.         KeyVal = tmpVal
  212.     Case REG_DWORD
  213.         bUseZero = False
  214.         ' format of keys in tmpVal :
  215.         ' e.g. in registry : (hex) : 40001  ==> reads : 4 0 1 (meaning : 04 00 01)
  216.         ' e.g. in registry : (hex) : 4000f  ==> reads : 4 0 15 (meaning : 04 00 f)
  217.         ' e.g. in registry : (hex) : 121326 ==> reads : 18 19 38 (meaning : 12 13 26)
  218.         sWorkStr = ""
  219.         For i = Len(tmpVal) To 1 Step -1
  220.             'check each code, get asci an convert to hex. You should have 2 digits
  221.             iChar = Asc(Mid(tmpVal, i, 1))
  222.             If iChar <> 0 Then
  223.                 bUseZero = True
  224.             End If
  225.             If bUseZero = True Then
  226.                 'make sure you have 2 digits (add extra 0 if necessary)
  227.                 If Len(Hex(iChar)) = 2 Then
  228.                     ' no need to add an extra 0
  229.                     sWorkStr = sWorkStr & Hex(iChar)
  230.                 Else
  231.                     sWorkStr = sWorkStr & "0" & Hex(iChar)
  232.                 End If
  233.             End If
  234.         Next
  235.         ' remove the leading 0: and add &h so you know it is hex
  236.         If Left(sWorkStr, 1) = "0" Then
  237.             sWorkStr = Right(sWorkStr, Len(sWorkStr) - 1)
  238.         End If
  239.         'if you want to know the value is stored as hex, use:
  240.         'KeyVal = "&h" & sWorkStr
  241.         'otherwise
  242.         KeyVal = sWorkStr
  243.     
  244.     Case REG_MULTI_SZ
  245.         tmpVal = Left(tmpVal, InStr(1, tmpVal, Chr(0), vbTextCompare) - 1)
  246.         KeyVal = tmpVal
  247.     End Select
  248.     
  249.     ReadRemoteReg = KeyVal
  250.     
  251.     'close the current key
  252.     RegCloseKey hKey
  253.     Exit Function
  254. Errore:
  255.     ReadRemoteReg = ""
  256.     RegCloseKey hKey
  257.     
  258. End Function
  259. Public Function GetDevTypesx() As Long
  260. Dim RegIndex As Long, CurKeyVal As String
  261. Dim DevClass As String, DevName As String
  262. NumDevTypes = -1
  263.  
  264. Dim hKey As Long
  265. Dim KeyValType As Long
  266. Dim KeyValSize As Long
  267. Dim KeyVal As String
  268. Dim tmpVal As String
  269. Dim res As Long
  270. Dim i As Integer
  271. Dim iChar As Integer
  272. Dim sChar, sWorkStr As String
  273. Dim bUseZero As Boolean
  274. Dim lReturnCode, lHive
  275.     
  276. 'open the specified key
  277. res = RegOpenKeyEx(lhRemoteRegistry, DriverKey, 0, KEY_ALL_ACCESS, hKey)
  278.  
  279.  
  280. CurKeyVal = String(255, 0)
  281. 'if the key is there to open, get the key value
  282. While RegEnumKeyEx(hKey, RegIndex, CurKeyVal, 255, 0, vbNullString, ByVal 0&, ByVal 0&) = 0
  283.     RegCloseKey hKey 'close the key
  284.     CurKeyVal = StripTerminator(CurKeyVal) 'trim the key value
  285.     
  286.     'get device class for win95 or other
  287.     If CI.ProductName = "Microsoft Windows 95" Then
  288.         DevClass = CurKeyVal
  289.     Else
  290.         DevClass = ReadRemoteReg(HKEY_LOCAL_MACHINE, DriverKey & "\" & CurKeyVal, "Class")
  291.         If DevClass = "" Then
  292.             DevClass = CurKeyVal
  293.         End If
  294.     End If
  295.     
  296.     
  297.     DevName = ReadRemoteReg(HKEY_LOCAL_MACHINE, DriverKey & "\" & CurKeyVal, "")
  298.     If DevName > "" Then  'if the returned value isn't empty
  299.         Incr NumDevTypes
  300.         ReDim Preserve DevTypes(NumDevTypes)
  301.         DevTypes(NumDevTypes).Class = DevClass  'add the device type to the array
  302.         DevTypes(NumDevTypes).Name = DevName
  303.     
  304.     End If
  305.     
  306.     RegIndex = RegIndex + 1 'increment the registry index
  307.     RegOpenKeyEx lhRemoteRegistry, DriverKey, 0, KEY_READ, hKey
  308.     CurKeyVal = String(255, 0) 'reset variable
  309. Wend
  310.  
  311. RegCloseKey hKey 'close registry key
  312. GetDevTypesx = NumDevTypes 'return number of devices found
  313.  
  314. End Function
  315.  
  316. Public Function GetWinVersion() As String
  317.     'if the computer is known to be NT based
  318.     If main.cmboWinVer.ListIndex = 1 Then
  319.         WinVersion = ReadRemoteReg(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", "CurrentVersion")
  320.     
  321.     'if the computer is known to be 9x based
  322.     ElseIf main.cmboWinVer.ListIndex = 0 Then
  323.         WinVersion = ReadRemoteReg(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion", "VersionNumber")
  324.     Else
  325.         'if we do not know, try both (assuming 9x first)
  326.         
  327.         'set the version to 9x
  328.         main.cmboWinVer.ListIndex = 0
  329.         WinVersion = ReadRemoteReg(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion", "VersionNumber")
  330.         If WinVersion = "" Then
  331.             'set the version to NT
  332.             main.cmboWinVer.ListIndex = 1
  333.             WinVersion = ReadRemoteReg(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", "CurrentVersion")
  334.         End If
  335.     End If
  336.     
  337.     'format version
  338.     WinVersion = Format(WinVersion, "0.00")
  339.     
  340.     'remove separator as it differs between localities
  341.     WinVersion = Left$(WinVersion, 1) & Right$(WinVersion, 2)
  342.     
  343.     'reset the treeview style just in case
  344.     main.TreeView1.Style = tvwTreelinesPlusMinusPictureText
  345.     
  346.     'retrieve the windows version
  347.     Select Case WinVersion
  348.     Case "510"
  349.         WinVersion = "NT"
  350.     Case "500"
  351.         WinVersion = "NT"
  352.     Case "490"
  353.         WinVersion = "9x"
  354.     Case "410"
  355.         WinVersion = "9x"
  356.     Case "400"
  357.         If main.cmboWinVer.ListIndex = 0 Then
  358.             WinVersion = "9x"
  359.         Else
  360.             WinVersion = "NT"
  361.             'i dont' know how NT4 determines active devices....
  362.             'so we'll just hide the icons
  363.             main.TreeView1.Style = tvwTreelinesPlusMinusText
  364.         End If
  365.     Case Else
  366.         MsgBox "Plese email the author with this information: " & WinVersion
  367.     End Select
  368.  
  369. End Function
  370.         
  371. Function StripTerminator(sInput As String) As String
  372.     Dim ZeroPos As Integer
  373.     'Search the first chr$(0)
  374.     ZeroPos = InStr(1, sInput, vbNullChar)
  375.     If ZeroPos > 0 Then
  376.         StripTerminator = Left$(sInput, ZeroPos - 1)
  377.     Else
  378.         StripTerminator = sInput
  379.     End If
  380.  
  381. End Function
  382.  
  383. Function FindInRegX(level As Long, ByVal CurKey As String, srchFor As String) As Long
  384. Dim hKey As Long
  385. Dim KeyValType As Long
  386. Dim KeyValSize As Long
  387. Dim KeyVal As String
  388. Dim tmpVal As String
  389. Dim res As Long
  390. Dim i As Integer
  391. Dim iChar As Integer
  392. Dim sChar, sWorkStr As String
  393. Dim bUseZero As Boolean
  394. Dim lReturnCode, lHive
  395. Dim CurKeyVal As String, strfound As String
  396. Dim CDevice As String
  397.  
  398.  
  399.     
  400.     If level = -1 Then Exit Function ' if we are out of levels, exit
  401.     
  402.     'open specified key
  403.     res = RegOpenKeyEx(lhRemoteRegistry, CurKey, 0, KEY_READ, hKey)
  404.     
  405.     CurKeyVal = String(255, 0) 'load the buffer
  406.     
  407.     If RegEnumKeyEx(hKey, Count(level), CurKeyVal, 255, 0, vbNullString, ByVal 0&, ByVal 0&) <> 0 Then
  408.         'if we are out of sublevels...
  409.         RegCloseKey hKey 'close the registry key
  410.         Count(level) = 0 'reset the count for this level
  411.         level = level - 1 'move to the previous level
  412.         'start searching again with the parent level
  413.         FindInRegX level, TruncString(CurKey, "\", True, False), srchFor
  414.         RegCloseKey hKey
  415.         Exit Function
  416.     Else
  417.         'if we have more sublevels to search...
  418.         RegCloseKey hKey 'close the current registry key
  419.         CurKeyVal = StripTerminator(CurKeyVal) 'trim the buffer
  420.        
  421.         CurKey = CurKey & "\" & CurKeyVal 'set the current key = to the new key
  422.  
  423.         'search for the device class for win95 or all other
  424.         If CI.ProductName = "Microsoft Windows 95" Then
  425.             strfound = UCase$(ReadRemoteReg(HKEY_LOCAL_MACHINE, CurKey, "Class"))
  426.         Else
  427.             strfound = UCase$(ReadRemoteReg(HKEY_LOCAL_MACHINE, DriverKey & "\" & ReadRemoteReg(HKEY_LOCAL_MACHINE, CurKey, "ClassGUID"), "Class"))
  428.         End If
  429.         
  430.         If strfound = UCase$(srchFor) Or UCase$(srchFor) = "ALL" And strfound <> "" Then
  431.             'we found a matching device, or the search is for all devices...
  432.             'make sure the device is a current one....
  433.             'CDevice = UCase$(ReadRemoteReg(HKEY_LOCAL_MACHINE, CurKey & "\Control", "DeviceReference"))
  434.             AddDeviceData strfound, CurKey  'add the device to the array
  435.             Count(level) = Count(level) + 1 'increment key# of this level
  436.             'start searching again on the parentlevel
  437.             FindInRegX level, TruncString(CurKey, "\", True, False), srchFor
  438.             RegCloseKey hKey
  439.             Exit Function
  440.         ElseIf strfound <> "" Then
  441.             'if we found a device class that doesn't match
  442.             Count(level) = Count(level) + 1 'increment key# of this level
  443.             'start searching again on the parent level
  444.             FindInRegX level, TruncString(CurKey, "\", True, False), srchFor
  445.             RegCloseKey hKey
  446.             Exit Function
  447.         Else
  448.             'if there is no "class" key in this level
  449.             Count(level) = Count(level) + 1 'increment key# of this level
  450.             level = level + 1 'go to the next level
  451.             'start searching again
  452.             FindInRegX level, CurKey, srchFor
  453.             RegCloseKey hKey
  454.             Exit Function
  455.         End If
  456.     End If
  457.  
  458. RegCloseKey hKey
  459. End Function
  460. Function FindInReg(DevType As String) As Long
  461.  
  462. NumExtraInfo = -1
  463. NumDevices = -1 'reset the number of devices found
  464. cntDeviceInfo = -1
  465. NumDevProps = -1
  466. 'Determine if the current OS is supported
  467. If DriverKey = "Unknown" Or DeviceKey = "Unknown" Then
  468.     MsgBox "This OS is currently not supported"
  469.     Exit Function
  470. End If
  471.  
  472. FindInRegX 0, DeviceKey, DevType 'start finding devices
  473. FindInReg = NumDevices 'return number of devices found
  474. End Function
  475. Function Incr(ByRef LongVar As Long)
  476.     LongVar = LongVar + 1
  477. End Function
  478. Function AddDeviceData(Class As String, Key As String)
  479.  
  480. NumExtDevProps = -1 'reset the number of extra device properties
  481. NumDevProps = -1 'reset the number of device properties
  482. NumDrvProps = -1 'reset the number or driver properties
  483.  
  484. Incr NumDevices 'increment +1
  485.  
  486. ReDim Preserve DeviceInfo(NumDevices) 'redim array
  487. ReDim Preserve DriverInfo(NumDevices) 'redim array
  488.  
  489. 'load information into the device array
  490. 'Get generic device information from device reg key
  491.  
  492. AddDevInfo NumDevices, vbNullString, "Class", Class
  493. AddDevInfo NumDevices, Key, "Compatible IDs", "CompatibleIds"
  494. AddDevInfo NumDevices, Key, "Device Description", "DeviceDesc"
  495. AddDevInfo NumDevices, Key, "Driver", "Driver"
  496. AddDevInfo NumDevices, vbNullString, "ExtraInfoID", "-1"
  497. AddDevInfo NumDevices, Key, "Friendly Name", "FriendlyName"
  498. AddDevInfo NumDevices, Key, "Hardware ID", "HardwareID"
  499. AddDevInfo NumDevices, Key, "Hardware Revision", "HWRevision"
  500. AddDevInfo NumDevices, Key, "Location Information", "LocationInformation"
  501. AddDevInfo NumDevices, Key, "Manufacturer", "Manufacturer"
  502. AddDevInfo NumDevices, Key, "Mfg", "Mfg"
  503. AddDevInfo NumDevices, vbNullString, "Registry Key", "HLM\" & Key
  504. AddDevInfo NumDevices, Key, "Service", "Service"
  505. AddDevInfo NumDevices, Key & "\Control", "In Use", "DeviceReference"
  506.  
  507. DriverPath = DriverKey & "\" & DeviceInfo(NumDevices).DevProps(3).PropVal
  508. 'get generic device information from driver reg key
  509. AddDrvInfo NumDevices, DriverPath, "Device Loader", "DevLoader"
  510. AddDrvInfo NumDevices, DriverPath, "Driver Date", "DriverDate"
  511. AddDrvInfo NumDevices, DriverPath, "Driver Description", "DriverDesc"
  512. AddDrvInfo NumDevices, DriverPath, "Driver Version", "DriverVersion"
  513. AddDrvInfo NumDevices, DriverPath, "INF Path", "InfPath"
  514. AddDrvInfo NumDevices, DriverPath, "INF Section", "InfSection"
  515. AddDrvInfo NumDevices, DriverPath, "INF Section Ext", "InfDriverExt"
  516. AddDrvInfo NumDevices, DriverPath, "Matching Device ID", "MatchingDeviceID"
  517. AddDrvInfo NumDevices, DriverPath, "Port Driver", "Port Driver"
  518. AddDrvInfo NumDevices, DriverPath, "Provider Name", "ProviderName"
  519.  
  520. 'get specific device information
  521. Select Case UCase(Class)
  522. Case "CDROM"
  523.     Incr NumExtraInfo
  524.     ReDim Preserve ExtraInfo(NumExtraInfo)
  525.     AddDevPropInfo NumExtraInfo, DriverPath, "Default DVD Region", "DefaultDVDRegion"
  526.     AddDevPropInfo NumExtraInfo, DriverPath, "Digital Audio Play", "DigitalAudioPlay"
  527.     DeviceInfo(NumDevices).DevProps(4).PropVal = NumExtraInfo
  528.  
  529. Case "DISPLAY"
  530.     Incr NumExtraInfo
  531.     ReDim Preserve ExtraInfo(NumExtraInfo)
  532.        
  533.     AddDevPropInfo NumExtraInfo, DriverPath, "CMDrivFlags", "CMDrivFlags"
  534.     AddDevPropInfo NumExtraInfo, DriverPath, "Private Problem", "PrivateProblem"
  535.     AddDevPropInfo NumExtraInfo, DriverPath, "Ver", "Ver"
  536.     
  537.     DeviceInfo(NumDevices).DevProps(4).PropVal = NumExtraInfo
  538. Case "MODEM"
  539.     '**********************************************************************
  540.     'the modem code for win95 (4.00 and 4.03) has only been verified on 1 machine
  541.     '**********************************************************************
  542.     If WinVersion = "Win95" Then
  543.         tKey = ReplaceText(TruncString(Key, "\", False, False), "&", "\")
  544.         'this call was based on my hardware config,
  545.         'it may not work on all win95 PC's
  546.         
  547.         Incr NumExtraInfo
  548.         ReDim Preserve ExtraInfo(NumExtraInfo)
  549.         
  550.         AddDevPropInfo NumExtraInfo, DeviceKey & "\" & tKey, "Attached To", "PortName"
  551.         DeviceInfo(NumDevices).DevProps(4).PropVal = NumExtraInfo
  552.     Else
  553.         Incr NumExtraInfo
  554.         ReDim Preserve ExtraInfo(NumExtraInfo)
  555.         
  556.         
  557.         AddDevPropInfo NumExtraInfo, DriverPath, "Attached To", "AttachedTo"
  558.         
  559.         'this is the case on my win98 laptop...
  560.         If ExtraInfo(NumExtraInfo).DevProps(0).PropVal = "" Then
  561.             ExtraInfo(NumExtraInfo).DevProps(0).PropVal = ReadRemoteReg(HKEY_LOCAL_MACHINE, Key, "PortName")
  562.         End If
  563.         
  564.         AddDevPropInfo NumExtraInfo, DriverPath, "Caller ID Outside", "CallerIDOutside"
  565.         AddDevPropInfo NumExtraInfo, DriverPath, "Caller ID Private", "CallerIDPrivate"
  566.         AddDevPropInfo NumExtraInfo, DriverPath, "Logging Path", "LoggingPath"
  567.         AddDevPropInfo NumExtraInfo, DriverPath, "Manufacturer", "Manufacturer"
  568.         AddDevPropInfo NumExtraInfo, DriverPath, "Model", "Model"
  569.         AddDevPropInfo NumExtraInfo, DriverPath, "Reset", "Reset"
  570.         
  571.         DeviceInfo(NumDevices).DevProps(4).PropVal = NumExtraInfo
  572.     End If
  573.  
  574. Case "MONITOR"
  575.     Incr NumExtraInfo
  576.     ReDim Preserve ExtraInfo(NumExtraInfo)
  577.     
  578.     AddDevPropInfo NumExtraInfo, DriverPath, "DPMS", "DPMS"
  579.     AddDevPropInfo NumExtraInfo, DriverPath, "Max Resolution", "MaxResolution"
  580.     DeviceInfo(NumDevices).DevProps(4).PropVal = NumExtraInfo
  581.  
  582. Case "PORTS"
  583.     Incr NumExtraInfo
  584.     ReDim Preserve ExtraInfo(NumExtraInfo)
  585.  
  586.     AddDevPropInfo NumExtraInfo, DriverPath, "Contention", "Contention"
  587.     AddDevPropInfo NumExtraInfo, DriverPath, "ECP Device", "ECPDevice"
  588.     AddDevPropInfo NumExtraInfo, DriverPath, "Enumerator", "Enumerator"
  589.     AddDevPropInfo NumExtraInfo, DriverPath, "Port Sub Class", "PortSubClass"
  590.     DeviceInfo(NumDevices).DevProps(4).PropVal = NumExtraInfo
  591.  
  592. Case "SYSTEM"
  593.     Incr NumExtraInfo
  594.     ReDim Preserve ExtraInfo(NumExtraInfo)
  595.     
  596.     AddDevPropInfo NumExtraInfo, DriverPath, "PCI Device", "PCIDevice"
  597.     AddDevPropInfo NumExtraInfo, DriverPath, "Resource Picker Exceptions", "ResourcePickerExceptions"
  598.     AddDevPropInfo NumExtraInfo, DriverPath, "Resource Picker Tags", "ResourcePickerTags"
  599.     
  600.     DeviceInfo(NumDevices).DevProps(4).PropVal = NumExtraInfo
  601.  
  602. End Select
  603.  
  604. End Function
  605. Private Function AddDevPropInfo(index As Long, RegPath As String, PropName As String, Propkey As String)
  606.  
  607. Incr NumExtDevProps
  608. ReDim Preserve ExtraInfo(NumExtraInfo).DevProps(NumExtDevProps)
  609.  
  610. ExtraInfo(index).DevProps(NumExtDevProps).PropDesc = PropName
  611. ExtraInfo(index).DevProps(NumExtDevProps).PropVal = ReadRemoteReg(HKEY_LOCAL_MACHINE, RegPath, Propkey)
  612.  
  613. End Function
  614. Private Function AddDevInfo(index As Long, RegPath As String, PropName As String, Propkey As String)
  615.  
  616. Incr NumDevProps
  617. ReDim Preserve DeviceInfo(NumDevices).DevProps(NumDevProps)
  618.  
  619. DeviceInfo(index).DevProps(NumDevProps).PropDesc = PropName
  620. If RegPath > "" Then
  621.     DeviceInfo(index).DevProps(NumDevProps).PropVal = ReadRemoteReg(HKEY_LOCAL_MACHINE, RegPath, Propkey)
  622. Else
  623.     DeviceInfo(index).DevProps(NumDevProps).PropVal = Propkey
  624. End If
  625.  
  626. End Function
  627. Private Function AddDrvInfo(index As Long, RegPath As String, PropName As String, Propkey As String)
  628.  
  629. Incr NumDrvProps 'increment +1
  630. ReDim Preserve DriverInfo(NumDevices).DevProps(NumDrvProps) 'resize array
  631.  
  632. DriverInfo(index).DevProps(NumDrvProps).PropDesc = PropName
  633. If RegPath > "" Then 'if the user want to find the val in the registry
  634.     DriverInfo(index).DevProps(NumDrvProps).PropVal = ReadRemoteReg(HKEY_LOCAL_MACHINE, RegPath, Propkey)
  635. Else
  636.     'if the user specified the value
  637.     DriverInfo(index).DevProps(NumDrvProps).PropVal = Propkey
  638. End If
  639.  
  640. End Function
  641. Function GetRegKeys()
  642. 'get the registry keys needed for the current OS
  643. Select Case WinVersion
  644. Case "NT"
  645.     DeviceKey = "SYSTEM\CurrentControlSet\Enum" 'the key containing device information
  646.     DriverKey = "SYSTEM\CurrentControlSet\Control\Class" 'the key containing driver information
  647. Case "9x"
  648.     DeviceKey = "Enum" 'the key containing device information
  649.     DriverKey = "SYSTEM\CurrentControlSet\Services\Class" 'the key containing driver information
  650. Case Else
  651.     'add info for other OS's
  652.     DeviceKey = "Unknown"
  653.     DriverKey = "Unknown"
  654. End Select
  655. End Function
  656.  
  657. Function TruncString(SText As String, SString As String, Front As Boolean, srchForward As Boolean) As String
  658. 'trims the rear/front off a string before/after a certain character
  659. If InStr(1, SText, SString) = False Then Exit Function
  660. If srchForward = True Then
  661.     'search from the start of string to the end returning
  662.     'before or after where it is found
  663.     If Front = True Then
  664.         TruncString = Left$(SText, InStr(1, SText, SString, vbTextCompare) - 1)
  665.     Else
  666.         TruncString = Right$(SText, Len(SText) - (InStr(1, SText, SString)))
  667.     End If
  668. Else
  669.     'search from end of string forward, returning string
  670.     'before or after where the string is found
  671.     If Front = True Then
  672.         TruncString = Left$(SText, InStrRev(SText, SString) - 1)
  673.     Else
  674.         TruncString = Right(SText, Len(SText) - InStrRev(SText, SString))
  675.     End If
  676. End If
  677. End Function
  678. Function TCase(strInput As String) As String
  679.     'convert string to Title Case
  680.     TCase = UCase$(Left$(strInput, 1)) & LCase$(Right$(strInput, Len(strInput) - 1))
  681. End Function
  682. Function ReplaceText(strInput As String, oText As String, rText As String) As String
  683.  
  684.  
  685. Dim sPosition As Long, FoundAt As Long
  686. sPosition = 1
  687. FoundAt = InStr(sPosition, strInput, oText,  Then
  688.     'se,er(sPosition, strInpn, strInpn, strInpn,  driver ins"
  689.     Ad  En'pcs, vbNullString, "Registry Keyi nins"
  690.   prInpn, stn Ad  En'p(t = True 
  691. s"
  692.     stry vProps)
  693.  
  694. ExtraInfo(index).De, n
  695.  before or l _ oText As StringMDI Device", " s oText As Strinsxt(ng))
  696.     Ad  En'pcs, vbNullString,  t or 3ExtraInfo)fied the valINfo NumEtri5ng
  697. sPosition = 1
  698. npn,tString)))
  699.   ', " s oText As Strinsxt(ng))
  700.     Ad  En'pcs, goTexeRsition egoTet As Stri String, Front As Boolean, srchForwariNumDevices, Key, "Mfg", "Mfg"
  701. AddDevInfo NTlg"
  702. Add.e O', " s oText As Strinsxt(ng))
  703.     Ad  En'pcs, d Function
  704. Fu0 As StnteTpcs, vbNullStrnd If
  705. End If
  706. Endsi from end ofYSs, vbNuliTpcs, vbN_ from mExte 
  707. s"
  708.  h
  709. AddDe e
  710. Else
  711.     'sElse
  712.     'sElse
  713.     'sElse
  714.     'sElse
  715.     'sElse
  716.     '
  717. Sv "ECP Dev"EC    AigCsition As Lon:aasLCLE>sition As ofopkreso
  718.  
  719. Exofopring, FrCtAs Lon:se
  720.    on
  721.  
  722. Exoh vbNuliTpcs, vbN_ from mExte 
  723. s"
  724.  h
  725. AddDe e
  726. Else
  727.     'sElse
  728.   pmDevPropse
  729.  lhe
  730.     om en opseOElse
  731.  bN_ froPstrInbN_ froPstrI FoundAt As Long
  732. sPfunctionKey_ from 4lStrinLerom 4lStrinLerom 4lStTi(Long
  733. sPfunctionKeyacnTPfunctionKvEn'pcs, goTexeRsition egoTet As S
  734.    sProps(4).PropVal =  sProps(4).PropVaom 4lStrinLerom 4lStTi(Long
  735. sPfunctioDevice"
  736.     Aeng, FrCtAs Laom 4lSte
  737.  erAs Laom 4lSte
  738.  erAs Laom 4lSte
  739.  (
  740.   4lSte
  741.  s oText As Strinsxt(nEetionKeyPropVal =  sPrtring) As nd If
  742. Endsi from i/aCLE> Adm 4lStrinLerom 4lSt0H_ 4lSte
  743.  erAs Laom 4lSte
  744.  erAsd.e
  745.  erAsnc
  746.  erAsnc
  747.  erA.e
  748.  erAHo  stryiaom 4lSt   Ad  rA.e
  749.  erAHoT)s"
  750. .
  751. ExoNT"
  752.   AHoT)s"
  753. .
  754. ExoNnlStTi(Lo Laom 4lSte, Front As Boolean, sre(g, Front", "Reset"
  755.         
  756.         DeviceInfo(NumDevices).DevProps(4).PropVal = NumExtraInfo
  757.    triCserve ExtraInfo(NumfieceDo NumExtraInfo, DriverPath, "Manufacturer", "Manuf DriverKey =PatrInbN_ fr0lg"
  758. Add.e O',mtpmDevPropse
  759.  lhe
  760.   I n(r oPatrInbN_ fr0lP_4       
  761.   
  762. .
  763. ExoNnlStTi(Lo Laom 4lSte, Fronvnc
  764.  erAsnc
  765.  erA.e
  766.  erAHo  stryiaom 4lSt   Ad  rA.tring, vbTextComparanuf DriverKey =PatrInbN_ oKpsed on my hardwariL "Reset"
  767.       dwariL "Reset"
  768.       dn
  769.   nfow"Pl erKey =PatrIHoT)serKey =Pg, Front As Boolean, srchForwariNumDevicesesetAs Bo
  770.  cesesetAsemg
  771.  nResourceP r
  772. ExoNnlStTi(Lo Laom 4lSte, FronpumDevice Str  DeviceInfo(NumDevices).Dserve ExtevPropse nResourh
  773. AddDevInfo NTlg"
  774. Add.e O', " s oText As Strinsxt(ng))
  775.     Ad  En'iL "ResenvnevPrviceInfo(NumDlg"
  776. AdderAHo  strlumfieceDoriCserve ExtraInfo(NumThesdderAHo  stAd aom 4lSt   Ad  rA.e
  777.  erAHoT)s"
  778. .
  779. ExoNT"
  780.   AHoT)s"
  781.  
  782.   )s"
  783. .
  784. Exs oText As Strins  Ad  En'iL "ResenvnevPrv  4lSt  tAHoT)s"
  785.  
  786.   )s FoundAt As LongrtName"T"
  787.   AHoT)s"
  788.  
  789.  inw.FoundAt AiPi)dNrKey =Patrr
  790. Ex=, DriverPath, "Mes"
  791.  
  792.   umDevices).Dse n(r oPatrInbN_ fr0lE umD ed  En'iL "Resenvneves).s os"ResensPositioAiPi2NatrInby =Patrr
  793. Ex=, O'iL "Resenvneve4PoiL "Resenvneves).s os"ResersisatrntrInpn, stves).s os"tAs Ad  En'ios"trr).s os"tA=Dy = "Enum" 'the key cve Exves).s os"Re NusEooos"Rs"tA=Dy = "Enum" nuoUe
  794.  erAH_la O',mtptioDeviceDy = "Enum" imDevices).Dse n(r oPatrInbN_ fr0lE umAd  En'iL "ReseeExves).s os"Re   lfKpsIh
  795. m" i = "Enum"L(r oPat"Re   lfKpeLEn'i "Resenvneve40"
  796.  
  797.   )s"
  798. .
  799. Exsse,er(sPositu  En'iL "Rparanuf DriverK os"Re   T)s"sEooos"Rs"tA=Dy = ofn, stn Ad  En'p(t = Tg string
  800.  
  801.  
  802. Di"T$(strImn, strumAd4lnvnevN_ fr0lEro"NTtves).s oseStmiL "RpaTtves).s o xs oTextt"Re   lfKpeLEn'nERpaLng
  803.  
  804.  
  805. Di"T$(De)Eooos"Rs"tA=Dy = "Enum" nuoUen
  806.  erAsn" Stri"ext As StmS= Tg y = "Enum" nuoUen
  807.  erAsn" nuoUelEr Ad  En'iL "RnmS= Ten
  808.  erAsn" nuoUelEr AdTnxt As SlnvnevN_ )
  809. Di"T$(De)EooossIh
  810. m" i = "Enum"L(r oi:ch from the start of string to the end returning
  811.     'before or aftersion
  812. Cnd If
  813. nAi = "Enum"L(r oi:ch from the start of string :ch froSstrInpn, strInpn,  driver ins"(r oi:cheImn, suoUe tion ewRL "EnumIcs, goTexeRsition egoTet As S
  814.    sProps(nnsxt(D(Uore or aftxon
  815. Cnd If
  816. nAi =p 'sElse
  817.     'sElse
  818.     'sElse
  819.     'sElse
  820.   oT)R
  821.     'sElse
  822. isatrntrInoi:cl
  823.    ).s os"Re wlStTi(Lo LaoR"'sElsese n(o
  824.          RegCloTVsProps(e1n(ssrPsEloPlay"
  825. Di"T$(De)d  rA.e
  826.  erAHoT)s"
  827. .loP:Enuion
  828. Cnd If
  829. S= Tg y)SVrInp p 's f
  830. End FunctionPi:cl
  831.    ).s onpn,  driver ins1Ni0irTcR$o,:cheImn RegPath > ""ing toh As y)Sg y)SVrs4n
  832. Cnd IfE paLng
  833. lnctionPi:wMyon
  834. Cnd If btionPi:wMyon
  835. U)UnPin'ios"trr).s os"teUen
  836.  erE ariver in(rever iftmiL "RpaTtves).s o xs oTextt"Re   lfKpeLEn'nEIrE ariver inr  rA.trxs oTextt"Re   lfo:zN0Beteach from the start of string :ch froSstrInpn, strInpn,  e FroNAw)Unfo
  837.     ReDi0SstrInpn, 'Myon
  838. U)UnPinTnfofo
  839.   onP
  840.  e(opVal = NumExtraInfo
  841.     End If
  842.  
  843. CasSSR,rops)erAHoT)s"
  844. .
  845. ExoNT"
  846.   AHoT)s"
  847.  
  848.   )s"eAvCvCvCvCvCvCvCvCvCvCvnevN_ fre0Nops erE ariver in(rever iftmiL "R,B )s FoundAt As LongrtNa = NumfLong
  849. mZSstrInp  NumfLong
  850. mZSsl NumfLong NumfLong
  851. mZSstrInp  NumfLong
  852. mZSsl+LumExtra
  853. Cnd If
  854. S=oPRInp  NumfLong
  855. mZSsl+LumExtra
  856. Cnd If
  857. S=oPRInp  NumfLong
  858. mZSsBongmuUtrau 4lStrinLerom )SVrs4n
  859. CnTVsProps(e1n(x0 NumfLong
  860. mZSslafrom mExte 
  861. Iem mExte 
  862. Iemtm t"hom mExte StrinLe> Ad