Private Sub SearchRegMachine()
Dim i As Integer
Dim lngKeyHandle As Long
Dim lngResult As Long
Dim lngCurIdx As Long
Dim strValue As String
Dim lngValueLen As Long
Dim strClass As String
Dim lngClassLen As Long
Dim strResult As String
Dim lngTime As FILETIME
Dim strSearch As String
Dim intSearchLen As Integer
Dim blnMatch As Boolean
'PlaySound App.path & "\StartReg.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC
i = 0
' Clear the current results
' Assign the new string to search for
strSearch = Text1.Text
intSearchLen = Len(strSearch)
' Open the Root Branch to search
lngResult = RegOpenKeyEx(strBranch, _
"", _
0&, _
KEY_READ, _
lngKeyHandle)
If lngResult <> ERROR_SUCCESS Then
MsgBox "Cannot open key.", , "Search Registry Keys"
Else
' If the Root branch can be opened, disable
' the buttons and begin the search
startscanregbutton.Enabled = False
' Command2.Enabled = False
listreg.Enabled = False
Reg.MousePointer = 11
lngCurIdx = 0
Do
lngValueLen = 2000
strValue = String(lngValueLen, 0)
lngClassLen = 2000
strClass = String(lngClassLen, 0)
' Enumerate all the sub keys
lngResult = RegEnumKeyEx(lngKeyHandle, _
lngCurIdx, _
ByVal strValue, _
lngValueLen, _
0&, _
ByVal strClass, _
lngClassLen, _
lngTime)
' Increment the index of found keys
lngCurIdx = lngCurIdx + 1
If lngResult = ERROR_SUCCESS Then
' Trim the current key to its actual length
strResult = Left(strValue, lngValueLen)
' Eliminate case if the search is insensitive
blnMatch = False
strValue = strResult
If Check1.Value = 0 Then
strResult = LCase(strResult)
strSearch = LCase(strSearch)
End If
' Compare strings based upon search type
Select Case Combo2.ListIndex
Case 0
' Check if any portion of the search string is found.
If InStr(strResult, strSearch) Then blnMatch = True
Case 1
' Check if an exact match is found.
If strResult = strSearch Then blnMatch = True
'Case 2
' Check if the search string matches the
' left portion of the key string.
' If Left(strResult, intSearchLen) = strSearch Then blnMatch = True
' Case Else
' Check if the search string matches the
' right portion of the key string.
'If Right(strResult, intSearchLen) = strSearch Then blnMatch = True
End Select
' Populate the list with keys that match
' the search criteria
If blnMatch Then
i = i + 1
listreg.AddItem strValue
End If
End If
' Keep looking for more keys
Loop While lngResult = ERROR_SUCCESS
' Close the Root Branch
lngResult = RegCloseKey(lngKeyHandle)
' Enable the buttons
Reg.MousePointer = 0
listreg.Enabled = True
startscanregbutton.Enabled = True
' Command2.Enabled = True
' Display the total matches
Label3.Caption = Str(i) & " Possible Problematic Registry Keys"
Text4.Text = "Scanning Complete" & Str(i) & " Possible Problematic Registry Keys Detected."
End If
End Sub