Results 1 to 8 of 8

Thread: registry check - freezing me

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    registry check - freezing me

    basically this is lagging my pc up when the registry has 0 entries in the key

    VB Code:
    1. Private Sub Form_Load()
    2. Dim RegArray() As String
    3. Dim intLoop As Integer
    4.  
    5.  RegArray = EnumKeyValues(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run")
    6.  
    7.  For intLoop = 0 To UBound(RegArray)
    8.      List1.AddItem RegArray(intLoop)
    9.  Next intLoop
    10.  
    11. 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
    Attached Files Attached Files

  2. #2
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: registry check - freezing me

    VB Code:
    1. Private Sub Form_Load()
    2.    Dim RegArray() As String
    3.    Dim intLoop As Integer
    4.  
    5.    On Error GoTo ErrEmptyKey
    6.    RegArray = EnumKeyValues(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run")
    7.    
    8.    For intLoop = 0 To UBound(RegArray)
    9.       List1.AddItem RegArray(intLoop)
    10.    Next intLoop
    11.    Exit Sub
    12. ErrEmptyKey:
    13.    If Err.Number = 9 Then Exit Sub 'RegArray not initialised - Empty key.
    14. End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: registry check - freezing me

    thanks but is there any other way without using on error?

  4. #4
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    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:
    1. If RegEnumKeyEx(hKey, Cnt, sSave, 255, 0, vbNullString, ByVal 0&, ByVal 0&) <> 0 Then
    2.    Exit Do
    3. 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.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: registry check - freezing me

    what about

    on error resume next ??

    i know its not recommended but would it cut the freezing?

  6. #6
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: registry check - freezing me

    Quote Originally Posted by Pouncer
    what about on error resume next ??
    Due to Hack already telling me off 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.
    Last edited by schoolbusdriver; Jul 2nd, 2006 at 03:41 AM.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: registry check - freezing me

    thanks i tried smething like this:

    VB Code:
    1. Do
    2.         'Create a buffer
    3.         sSave = String(255, 0)
    4.         'enumerate the values
    5.         If RegEnumValue(hKey, Cnt, sSave, 255, 0, ByVal 0&, ByVal 0&, ByVal 0&) <> 0 Then
    6.             Exit Do
    7.             strKeys(0) = "Nothing"
    8.         Else
    9.             '   Add the Keys to the array.
    10.             ReDim Preserve strKeys(Cnt)
    11.             strKeys(Cnt) = StripTerminator(sSave)
    12.             Cnt = Cnt + 1
    13.         End If
    14.     Loop
    15.    
    16.     'Close the registry
    17.     RegCloseKey hKey
    18.    
    19.     EnumKeyValues = strKeys

    and then..

    VB Code:
    1. Dim RegArray() As String
    2.    Dim intLoop As Integer
    3.    
    4.  
    5.    RegArray = EnumKeyValues(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run")
    6.    
    7.    If (RegArray(0) <> "Nothing") Then  
    8.    For intLoop = 0 To UBound(RegArray)
    9.       List1.AddItem RegArray(intLoop)
    10.    Next intLoop
    11.    End If

    but that still doesnt work, still gives error 9 because it doesnt set RegArray(0) to ''Nothing''
    Last edited by Pouncer; Jul 2nd, 2006 at 04:04 AM.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: registry check - freezing me

    ive solved it:

    VB Code:
    1. Do
    2.         'Create a buffer
    3.         sSave = String(255, 0)
    4.         'enumerate the values
    5.         If RegEnumValue(hKey, Cnt, sSave, 255, 0, ByVal 0&, ByVal 0&, ByVal 0&) <> 0 Then
    6.            
    7.             If (switch = False) Then
    8.                 ReDim Preserve strKeys(0)
    9.                 strKeys(0) = "Nothing"
    10.             End If
    11.             Exit Do
    12.         Else
    13.             switch = True
    14.             '   Add the Keys to the array.
    15.             ReDim Preserve strKeys(Cnt)
    16.             strKeys(Cnt) = StripTerminator(sSave)
    17.             Cnt = Cnt + 1
    18.         End If
    19.     Loop
    20.    
    21.     'Close the registry
    22.     RegCloseKey hKey
    23.    
    24.     EnumKeyValues = strKeys

    VB Code:
    1. Private Sub Command1_Click()
    2.         Dim RegArray() As String
    3.         Dim intLoop As Integer
    4.    
    5.         RegArray = EnumKeyValues(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\RunOnce")
    6.  
    7.         MsgBox RegArray(0)
    8.        
    9.         If (RegArray(0) <> "Nothing") Then
    10.        
    11.             For intLoop = 0 To UBound(RegArray)
    12.                 Dim reg_str, entx As String
    13.                
    14.                 Debug.Print RegArray(intLoop)
    15.             Next intLoop
    16.         End If
    17. End Sub

    works perfect now!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width