home *** CD-ROM | disk | FTP | other *** search
/ Using Visual Basic 5 (Platinum Edition) / vb5.iso / Code / ch45 / chp533a.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-07-06  |  6.3 KB  |  211 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
  3. Begin VB.Form frmchp533 
  4.    Caption         =   "Registry Explorer"
  5.    ClientHeight    =   3930
  6.    ClientLeft      =   2010
  7.    ClientTop       =   1545
  8.    ClientWidth     =   9045
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3930
  11.    ScaleWidth      =   9045
  12.    Begin VB.ListBox lstValues 
  13.       Height          =   1620
  14.       Left            =   5160
  15.       TabIndex        =   3
  16.       Top             =   480
  17.       Width           =   3915
  18.    End
  19.    Begin ComctlLib.TreeView treReg 
  20.       Height          =   3735
  21.       Left            =   360
  22.       TabIndex        =   1
  23.       Top             =   0
  24.       Width           =   4755
  25.       _ExtentX        =   8387
  26.       _ExtentY        =   6588
  27.       _Version        =   327680
  28.       LineStyle       =   1
  29.       Style           =   7
  30.       Appearance      =   1
  31.       MouseIcon       =   "chp533a.frx":0000
  32.    End
  33.    Begin VB.CommandButton cmdExit 
  34.       Caption         =   "E&xit"
  35.       Height          =   315
  36.       Left            =   8100
  37.       TabIndex        =   0
  38.       Top             =   3240
  39.       Width           =   915
  40.    End
  41.    Begin VB.Label lblValue 
  42.       Caption         =   "Values"
  43.       Height          =   315
  44.       Left            =   5340
  45.       TabIndex        =   2
  46.       Top             =   60
  47.       Width           =   1995
  48.    End
  49. Attribute VB_Name = "frmchp533"
  50. Attribute VB_GlobalNameSpace = False
  51. Attribute VB_Creatable = False
  52. Attribute VB_PredeclaredId = True
  53. Attribute VB_Exposed = False
  54. Option Explicit
  55. Private Sub Command1_Click()
  56. End Sub
  57. Private Sub cmdExit_Click()
  58. Unload Me
  59. End Sub
  60. Private Sub Form_Load()
  61. Dim ntest As Long
  62. Dim cname As String
  63. Dim lname As Long
  64. Dim x As Integer
  65. Dim nodX As Node
  66. Screen.MousePointer = vbHourglass
  67. cname = Space$(4096)
  68. lname = 4096
  69. Set nodX = treReg.Nodes.Add(, , "HKEY_CLASSES_ROOT", "HKEY_CLASSES_ROOT")
  70. Set nodX = treReg.Nodes.Add(, , "HKEY_CURRENT_USER", "HKEY_CURRENT_USER")
  71. Set nodX = treReg.Nodes.Add(, , "HKEY_LOCAL_MACHINE", "HKEY_LOCAL_MACHINE")
  72. Set nodX = treReg.Nodes.Add(, , "HKEY_USERS", "HKEY_USERS")
  73. Set nodX = treReg.Nodes.Add(, , "HKEY_CURRENT_CONFIG", "HKEY_CURRENT_CONFIG")
  74. Set nodX = treReg.Nodes.Add(, , "HKEY_DYN_DATA", "HKEY_DYN_DATA")
  75. x = 0
  76. Do While ntest = 0
  77.     ' get all of the Sub Keys for HKEY_CLASSES_ROOT
  78.     ntest = RegEnumKey(HKEY_CLASSES_ROOT, x, cname, lname)
  79.     If ntest = 0 Then
  80.         
  81.         Set nodX = treReg.Nodes.Add("HKEY_CLASSES_ROOT", tvwChild, "A" & CStr(x), cname)
  82.         x = x + 1
  83.         
  84.     End If
  85. x = 0
  86. ntest = 0
  87. Do While ntest = 0
  88.     ' get all of the Sub Keys for HKEY_CURRENT_USER
  89.     ntest = RegEnumKey(HKEY_CURRENT_USER, x, cname, lname)
  90.     If ntest = 0 Then
  91.         
  92.         Set nodX = treReg.Nodes.Add("HKEY_CURRENT_USER", tvwChild, "B" & CStr(x), cname)
  93.         x = x + 1
  94.     End If
  95. x = 0
  96. ntest = 0
  97. Do While ntest = 0
  98.     ' get all of the Sub Keys for HKEY_LOCAL_MACHINE
  99.     ntest = RegEnumKey(HKEY_LOCAL_MACHINE, x, cname, lname)
  100.     If ntest = 0 Then
  101.         Set nodX = treReg.Nodes.Add("HKEY_LOCAL_MACHINE", tvwChild, "C" & CStr(x), cname)
  102.         x = x + 1
  103.     End If
  104. x = 0
  105. ntest = 0
  106. Do While ntest = 0
  107.     ' get all of the Sub Keys for HKEY_USERS
  108.     ntest = RegEnumKey(HKEY_USERS, x, cname, lname)
  109.     If ntest = 0 Then
  110.         
  111.         Set nodX = treReg.Nodes.Add("HKEY_USERS", tvwChild, "D" & CStr(x), cname)
  112.         x = x + 1
  113.     End If
  114. x = 0
  115. ntest = 0
  116. Do While ntest = 0
  117.     ' get all of the Sub Keys for HKEY_CURRENT_CONFIG
  118.     ntest = RegEnumKey(HKEY_CURRENT_CONFIG, x, cname, lname)
  119.     If ntest = 0 Then
  120.         
  121.         Set nodX = treReg.Nodes.Add("HKEY_CURRENT_CONFIG", tvwChild, "E" & CStr(x), cname)
  122.         x = x + 1
  123.     End If
  124. x = 0
  125. ntest = 0
  126. Do While ntest = 0
  127.     ' get all of the Sub Keys for HKEY_DYN_DATA
  128.     ntest = RegEnumKey(HKEY_DYN_DATA, x, cname, lname)
  129.     If ntest = 0 Then
  130.         
  131.         Set nodX = treReg.Nodes.Add("HKEY_DYN_DATA", tvwChild, "F" & CStr(x), cname)
  132.         x = x + 1
  133.     End If
  134. Screen.MousePointer = vbDefault
  135. End Sub
  136. Private Sub Form_Unload(Cancel As Integer)
  137. Set frmchp533 = Nothing
  138. End Sub
  139. Private Sub treReg_NodeClick(ByVal Node As ComctlLib.Node)
  140. Dim nodX As Node
  141. Dim ntest As Integer
  142. Dim lret As Long
  143. Dim hKey As Long
  144. Dim x As Integer
  145. Dim cname As String
  146. Dim cvname As String
  147. Dim ctype As String
  148. Dim lpcvalue As Long
  149. Dim lname As Long
  150. Dim lhandle As Long
  151. Dim ntype As Long
  152. Dim cdata As Byte
  153. Dim ldata As Long
  154. cname = Space$(4096)
  155. cvname = Space$(25)
  156. lname = 4096
  157. 'cdata = Space$(4096)
  158. ldata = Len(cdata)
  159. If Node.Children > 0 Then
  160.     Exit Sub
  161. Select Case Mid$(Node.FullPath, 1, InStr(1, Node.FullPath, "\") - 1)
  162. Case "HKEY_CLASSES_ROOT"
  163.     hKey = HKEY_CLASSES_ROOT
  164. Case "HKEY_CURRENT_CONFIG"
  165.     hKey = HKEY_CURRENT_CONFIG
  166. Case "HKEY_CURRENT_USER"
  167.     hKey = HKEY_CURRENT_USER
  168. Case "HKEY_DYN_DATA"
  169.     hKey = HKEY_DYN_DATA
  170. Case "HKEY_LOCAL_MACHINE"
  171.     hKey = HKEY_LOCAL_MACHINE
  172. Case "HKEY_PERFORMANCE_DATA"
  173.     hKey = HKEY_PERFORMANCE_DATA
  174. Case "HKEY_USERS"
  175.     hKey = HKEY_USERS
  176. End Select
  177. lret = RegOpenKeyEx(hKey, Mid$(Node.FullPath, InStr(1, Node.FullPath, "\") + 1, Len(Node.FullPath) - InStr(1, Node.FullPath, "\") + 1), 0, KEY_QUERY_VALUE, lhandle)
  178. If lret <> 0 Then
  179.     Exit Sub
  180. End If
  181. ntest = 0
  182. x = 0
  183. Do While ntest <> ERROR_NO_MORE_ITEMS
  184.     ntest = RegEnumKey(lhandle, x, cname, lname)
  185.     If ntest = 0 Then
  186.         Set nodX = treReg.Nodes.Add(Node.Index, tvwChild, "A" & CStr(x) & CStr(Timer), cname)
  187.         x = x + 1
  188.     Else
  189.         ntest = 0
  190.         x = 0
  191.         lstValues.Clear
  192.         Do While ntest <> ERROR_NO_MORE_ITEMS
  193.            
  194.             
  195.             ntest = RegEnumValue(lhandle, x, cvname, Len(cvname), 0, ntype, cdata, ldata)
  196.             If ntest = 0 Then
  197.             
  198.                lstValues.AddItem Trim$(cvname)
  199.                 x = x + 1
  200.             
  201.             End If
  202.         
  203.         Loop
  204.     End If
  205. End If
  206. lret = RegCloseKey(lhandle)
  207. If Node.Children <> 0 Then
  208.     Node.Expanded = True
  209. End If
  210. End Sub
  211.