1 Attachment(s)
registry check - freezing me
basically this is lagging my pc up when the registry has 0 entries in the key
VB Code:
Private Sub Form_Load()
Dim RegArray() As String
Dim intLoop As Integer
RegArray = EnumKeyValues(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run")
For intLoop = 0 To UBound(RegArray)
List1.AddItem RegArray(intLoop)
Next intLoop
End Sub
for e.g, if my HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run has no entries, it will just lag me right down, its like its in an endless loop or something.
can anyone help me sort this problem out?
this is the module i use
Re: registry check - freezing me
VB Code:
Private Sub Form_Load()
Dim RegArray() As String
Dim intLoop As Integer
On Error GoTo ErrEmptyKey
RegArray = EnumKeyValues(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run")
For intLoop = 0 To UBound(RegArray)
List1.AddItem RegArray(intLoop)
Next intLoop
Exit Sub
ErrEmptyKey:
If Err.Number = 9 Then Exit Sub 'RegArray not initialised - Empty key.
End Sub
Re: registry check - freezing me
thanks but is there any other way without using on error?
Re: registry check - freezing me
Erm... No. The problem lies in the bas module, because there's little to no error checking in it. In this case the call has failed because of an empty subkey. If you look at the module's code:-
VB Code:
If RegEnumKeyEx(hKey, Cnt, sSave, 255, 0, vbNullString, ByVal 0&, ByVal 0&) <> 0 Then
Exit Do
Else
it's saying "if it fails, exit". So the form's code never gets anything returned to it, so that in turn fails - with a different error. Either way you have to find out why RegEnumKeyEx failed and compensate for it.
Re: registry check - freezing me
what about
on error resume next ??
i know its not recommended but would it cut the freezing?
Re: registry check - freezing me
Quote:
Originally Posted by Pouncer
what about on error resume next ??
Due to Hack already telling me off :bigyello: for daring to suggest it in another post, I can't recommend it. But for testing purposes... ;) . What the bas module lacks is an error function to handle all the errors raised in all the subs/functions, i.e, the call might fail because of a corrupted keyname rather than the subkey being empty. (It happens - I remember when I'd installed a faulty memory stick in a PC...)
EDIT:- Remember though, all OERN does is hide a problem, not remove it.
Re: registry check - freezing me
thanks i tried smething like this:
VB Code:
Do
'Create a buffer
sSave = String(255, 0)
'enumerate the values
If RegEnumValue(hKey, Cnt, sSave, 255, 0, ByVal 0&, ByVal 0&, ByVal 0&) <> 0 Then
Exit Do
strKeys(0) = "Nothing"
Else
' Add the Keys to the array.
ReDim Preserve strKeys(Cnt)
strKeys(Cnt) = StripTerminator(sSave)
Cnt = Cnt + 1
End If
Loop
'Close the registry
RegCloseKey hKey
EnumKeyValues = strKeys
and then..
VB Code:
Dim RegArray() As String
Dim intLoop As Integer
RegArray = EnumKeyValues(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run")
If (RegArray(0) <> "Nothing") Then
For intLoop = 0 To UBound(RegArray)
List1.AddItem RegArray(intLoop)
Next intLoop
End If
but that still doesnt work, still gives error 9 because it doesnt set RegArray(0) to ''Nothing''
Re: registry check - freezing me
ive solved it:
VB Code:
Do
'Create a buffer
sSave = String(255, 0)
'enumerate the values
If RegEnumValue(hKey, Cnt, sSave, 255, 0, ByVal 0&, ByVal 0&, ByVal 0&) <> 0 Then
If (switch = False) Then
ReDim Preserve strKeys(0)
strKeys(0) = "Nothing"
End If
Exit Do
Else
switch = True
' Add the Keys to the array.
ReDim Preserve strKeys(Cnt)
strKeys(Cnt) = StripTerminator(sSave)
Cnt = Cnt + 1
End If
Loop
'Close the registry
RegCloseKey hKey
EnumKeyValues = strKeys
VB Code:
Private Sub Command1_Click()
Dim RegArray() As String
Dim intLoop As Integer
RegArray = EnumKeyValues(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\RunOnce")
MsgBox RegArray(0)
If (RegArray(0) <> "Nothing") Then
For intLoop = 0 To UBound(RegArray)
Dim reg_str, entx As String
Debug.Print RegArray(intLoop)
Next intLoop
End If
End Sub
works perfect now!!