|
-
May 1st, 2008, 12:15 AM
#1
Thread Starter
PowerPoster
Searching with a list box instead of a textbox.
Hey guys I have a sub that searches for registry keys I enter in a textbox its caled text1.
The sub that scans is this ..
VB Code:
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
Now basically what it does is searches for registry keys that are inputed in text1 and ptus the result in listreg.
Now is there a way to change it so instead of searching for one at a time in a textbox, it searchs from keys loaded to a listbox one at a time.
Can anyone tell me how to do that?
Thanks!
-
May 1st, 2008, 01:36 AM
#2
Frenzied Member
Re: Searching with a list box instead of a textbox.
a simple change can do it
Change the sub header to
Code:
Private Sub SearchRegMachine(Byval strSearch as String)
Remove the
Dim strSearch As String and strSearch = Text1.Text within the sub.
say you list is list1
Code:
Dim i As Long
For i = 0 To list1.ListCount - 1
SearchRegMachine list1.List(i)
Next
would do it
-
May 1st, 2008, 04:18 AM
#3
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
Ok, thanks.
Umm I get an arugment not optional error when I try to call the sub.
Since the subs name changed, how would I call it now?
-
May 1st, 2008, 04:32 AM
#4
Re: Searching with a list box instead of a textbox.
 Originally Posted by Justin M
Umm I get an arugment not optional error when I try to call the sub.
Look at the help for the error - it tells you that the sub/function needs more parameters than you passed to it.
Since the subs name changed,
erm.. it was SearchRegMachine, and still is.
See the second half of zeezee's post (from "say" onwards), it contains an example - which would not give the error you got.
-
May 1st, 2008, 04:42 AM
#5
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
I think I see what you mean, but when I go to scan the registry now I get the arrugment not optional and it highlights the code "Call SearchRegMachine"
in the block of code
VB Code:
Private Sub startscanregbutton_Click() listreg.Clear Text3.Text = Text3.Text & vbNewLine & "Scanning in progress...Please Wait.." Combo1.ListIndex = 0 Call SearchRegMachine Combo1.ListIndex = 1 Call SearchRegMachine Text3.Text = Text3.Text & vbNewLine & Text4.Text End Sub
-
May 1st, 2008, 04:45 AM
#6
Re: Searching with a list box instead of a textbox.
Of course it does - compare that line (in fact, lines 4 to 9) with zeezee's example.
-
May 1st, 2008, 04:51 AM
#7
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
But his code to switch from text1 to the list was put in the sub - the SearchRegMachine
-
May 1st, 2008, 04:59 AM
#8
Re: Searching with a list box instead of a textbox.
 Originally Posted by Justin M
But his code to switch from text1 to the list was put in the sub - the SearchRegMachine
Try this
Code:
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
Dim intListCount As Integer
For intListCount = 0 To List1.ListCount
strSearch = List1.List(intListCount)
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
Next
End Sub
-
May 1st, 2008, 05:05 AM
#9
Re: Searching with a list box instead of a textbox.
 Originally Posted by Justin M
But his code to switch from text1 to the list was put in the sub - the SearchRegMachine
No it wasn't - zeezee's example (from "say" onwards) was example usage, and is the equivalent of lines 4 to 9 of your code in post #5, but without the errors.
All you needed to do was change list1 to Combo1.
-
May 1st, 2008, 08:32 PM
#10
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
Ok do you mean I add this code then
Dim ix As Long
For ix = 0 To Combo1.ListCount - 1
SearchRegMachine Combo1.List(ix)
Next
But I still get an argument not optional error when I call the SearchRegMachine sub
-
May 1st, 2008, 09:24 PM
#11
Frenzied Member
Re: Searching with a list box instead of a textbox.
Hey Justin, can you post the New SearchRegMachine again.
At least the sub header ?
-
May 1st, 2008, 09:31 PM
#12
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
Absolutely
VB Code:
Private Sub SearchRegMachine(ByVal strSearch As String) 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 Dim ix As Long For ix = 0 To Combo1.ListCount - 1 SearchRegMachine Combo1.List(ix) Next 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, lngTimex) ' 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
-
May 1st, 2008, 09:55 PM
#13
Frenzied Member
Re: Searching with a list box instead of a textbox.
-
May 1st, 2008, 09:59 PM
#14
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
Ohh, the sub gets called here
VB Code:
Private Sub startscanregbutton_Click() listreg.Clear Text3.Text = Text3.Text & vbNewLine & "Scanning in progress...Please Wait.." Combo1.ListIndex = 0 Call SearchRegMachine Combo1.ListIndex = 1 Call SearchRegMachine Text3.Text = Text3.Text & vbNewLine & Text4.Text End Sub
-
May 1st, 2008, 10:09 PM
#15
Frenzied Member
Re: Searching with a list box instead of a textbox.
You see, thats why its not wroking
Code:
Call SearchRegMachine
has no arguments, Thats the reason.
Ok that event procedure should look like this
Code:
Private Sub startscanregbutton_Click()
Dim ix As Long
listreg.Clear
Text3.Text = Text3.Text & vbNewLine & "Scanning in progress...Please Wait.."
For ix = 0 To Combo1.ListCount - 1
SearchRegMachine Combo1.List(ix)
Next
Text3.Text = Text3.Text & vbNewLine & Text4.Text
End Sub
few tips.
Code:
Label3.Caption = Str(i) & " Possible Problematic Registry Keys"
Text4.Text = "Scanning Complete" & Str(i) & " Possible Problematic Registry Keys Detected."
This part inside the SearchRegMachine should also come out.
In the Private Sub startscanregbutton_Click() , after the loop, put it like this
Code:
Label3.Caption = Str(listreg.ListCount) & " Possible Problematic Registry Keys"
Text4.Text = "Scanning Complete" & Str(listreg.ListCount) & " Possible
Problematic Registry Keys Detected."
Try and see
-
May 1st, 2008, 10:24 PM
#16
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
Ok, but I get an error, that variable lngTimex is not defined inthe line of code.
VB Code:
lngResult = RegEnumKeyEx(lngKeyHandle, lngCurIdx, ByVal strValue, lngValueLen, 0&, ByVal strClass, lngClassLen, lngTimex)
this is in the searchregmachiensub
-
May 1st, 2008, 10:36 PM
#17
Frenzied Member
Re: Searching with a list box instead of a textbox.
that variable lngTimex is not defined inthe line of code.
Hmm. the Error is self explanatory. You haven't defined the variable.
Check that line against the code in your first post. You will see the difference. 
-
May 1st, 2008, 10:49 PM
#18
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
Well which sub should I use, the one in my first post or the modified one.
Cause the one in the first post only scans for reg keys manually enter in text1. I would like to have it search for each item in a list2 lsitbox instead.
-
May 1st, 2008, 10:57 PM
#19
Frenzied Member
Re: Searching with a list box instead of a textbox.
no no.
Lets resolve it like this.
We changed the sub in post #1 to the new one.
What we changed was, the sub header, and the string to search part.
Nothing else
You need the new one to search for multiple keys. right?
So this last error , is due to a change, which was not mentioned here.
And as the error says, you haven't declared the variable.
But if you compare that line with the new one, you should the spot the error.
Its pretty simple.
Don't get this wrong, I can tell exactly how to resolve the error, but since this a simple error , and you being unable to resolve that, is not good. Thats why I think its better you understand whats the error and how to resolve it. 
(BTW If you need to resolve it, just say, I ll tell how )
Cheers!
-
May 1st, 2008, 11:13 PM
#20
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
lol i think I see the prob lngTimex is not real.
It was a typo its supposed to be lngTime
So does this mean I still need to enter keys in text1? But now I just click on a item in list2 and it goes to text1?
-
May 1st, 2008, 11:31 PM
#21
-
May 2nd, 2008, 12:09 AM
#22
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
Well what the combo box does is set what you search in.
Like for one instance I search in the HKEY_LOCAL_MACHINE and another time in the
HKEY_USERS
which is why I had the code
Combo1.ListIndex = 0
Combo1.ListIndex = 1
in the button code to search.
-
May 2nd, 2008, 02:03 AM
#23
Frenzied Member
Re: Searching with a list box instead of a textbox.
ok clarification
 Originally Posted by In Post #1
Now is there a way to change it so instead of searching for one at a time in a textbox, it searchs from keys loaded to a listbox one at a time.
this asks how to do the search for multiple values in a list box.
I am assuming that this Combo1 is the list you have mentioned,
Is that right?
-
May 2nd, 2008, 05:28 AM
#24
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
my combo1 is a drop down box.
list2 is where all the keys I want to search for are.
-
May 2nd, 2008, 07:51 AM
#25
Frenzied Member
Re: Searching with a list box instead of a textbox.
so the values to be searched are in list2?
so you have some registry keys in List2, and you want to search whether these keys are in the registry?
If this is true, what is Combo1?
-
May 2nd, 2008, 01:17 PM
#26
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
ITs where you can pick between to search in the HKEY_LOCAL_MACHINE OR the
HKEY_USERS
-
May 2nd, 2008, 10:38 PM
#27
Frenzied Member
Re: Searching with a list box instead of a textbox.
ok next question, if the Combo1 has the starting point and list1 has the keys, where do these values get used in your SearchRegMachine method?
I believe that the heart of this method is RegOpenKeyEx and RegEnumKeyEx
If that is so, in which part are these values in Combo1 and List1 are used?
Can you give an example on how you intend to use them?
-
May 2nd, 2008, 10:59 PM
#28
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
list2 has the keys
see the searchregmachine is currently set up to work with text1 which only holds 1 key at a time. I was wondering how to get it so it would search they keys in list2.
Or have it so when the scan button is pressed, each key in the list2 is put in the text1.text and each key is scanned for one at a time.
-
May 2nd, 2008, 11:12 PM
#29
Frenzied Member
Re: Searching with a list box instead of a textbox.
-
May 2nd, 2008, 11:33 PM
#30
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
lol the combo 1 is where you pick what part of the registry to scan, its in the scanregmachine.
that above code should be list2, i just noticed that now lol
-
May 2nd, 2008, 11:39 PM
#31
Frenzied Member
Re: Searching with a list box instead of a textbox.
lol the combo 1 is where you pick what part of the registry to scan, its in the scanregmachine.
ok there is a Combo2 there, but not Combo1,
It was there and we removed it i think.
ok ok, now does it work correctly with above code changed to list2?
-
May 2nd, 2008, 11:47 PM
#32
Thread Starter
PowerPoster
Re: Searching with a list box instead of a textbox.
It does scan I can see that.
The odd thing, which may be in the prog itself since i got this code from the microsoft webiste.
It does not pick up things.
Though I am not too sure how to format the items.
I enter things like this in list2
HKEY_CURRENT_USER\software\winspykiller mscheduledscan
or even HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Default_Page_Url
but it does not pick it up.
-
May 3rd, 2008, 02:11 AM
#33
Frenzied Member
-
May 3rd, 2008, 02:14 AM
#34
Re: Searching with a list box instead of a textbox.
Justin: Have you read and understood the code you obtained?
I don't think it's doing what you expect and, as it is, will not work.
This call:
Code:
lngResult = RegOpenKeyEx(strBranch, _
"", _
0&, _
KEY_READ, _
lngKeyHandle)
will fail with a Type Mismatch since it expects a Long value as opposed to a string for the Root Key,
eg one of these:
Code:
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
'
' and in your code, for example:
'
lngKey = HKEY_CURRENT_USER
lngResult = RegOpenKeyEx(lngKey, _
"", _
0&, _
KEY_READ, _
lngKeyHandle)
Also this statement
Code:
If InStr(strResult, strSearch) Then blnMatch = True
'
' Should be
'
If InStr(strSearch, strResult) Then blnMatch = True
The code only enumerates keys one level down from the root
eg
HKEY_CURRENT_USER\Software
so if you specified
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Default_Page_Url
as your search, and looked for a partial match (ie Combo2.ListIndex = 0) it would find 'Software' and insert that into the ListBox. If you performed an exact match (Combo2.ListIndex = 1) it would not find anything.
To eumerate all the way down the structure would need some fairly significant modifications to the existing code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|