CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: RegRead error

  1. #1
    Join Date
    Jul 2004
    Posts
    4

    RegRead error

    How can i find out if the RegRead operation was successful?

  2. #2
    Join Date
    Feb 2003
    Location
    Hyderabad
    Posts
    181
    whats this message is related to
    Ritesh Tandon
    (Sr. Software Engineer)

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    wscripting technology?
    Then: if you read something different by default values of type of key_value
    you're reading, you read something.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    RegRead will create an automation error, so you can use ON ERROR to determine if is was successfull or not in reading, say for example:

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    On Error GoTo ErrReadingRegistry
    
        Dim objShell As New WshShell
        Dim strReturn As String
         
        'This works "Systemtray"
        strReturn = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Systemtray")
         
        MsgBox strReturn
         
         
        'This doesnt "Systemtray OOOPPPSS" and return an error
        strReturn = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Systemtray OOOPPPSS")
         
        MsgBox strReturn
         
        Exit Sub
    
    ErrReadingRegistry:
         
        MsgBox "Error # " & Err.Number & vbCrLf & _
            "Description: " & Err.Description
         
    End Sub
    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  5. #5
    Join Date
    Nov 2002
    Posts
    82
    Hallo Savitar,

    here another way to do it


    Code:
    '==========================================================
    ' Name: ERROR_SUCCESS
    ' Purpose: All the access bits, not including MAXIMUM_ALLOWED,
    '   are granted and the GrantedAccessMask member is not zero.
    ' Remarks:
    '==========================================================
    Public Const ERROR_SUCCESS = 0&
    
    '==========================================================
    ' Name: ERROR_CODE
    ' Purpose: Error code
    ' Remarks:
    '==========================================================
    Public Const ERROR_CODE = -1&
    
    
    '==========================================================
    ' Name: fWSHGetRegKey
    ' Input:
    '   ByRef STRNAME As String
    '   ByRef vValue As Variant
    ' Output: Long
    ' Purpose: Returns the value of a key or value-name from the registry
    ' for the following value type REG_SZ, REG_DWORD, REG_BINARY,
    ' REG_EXPAND_SZ, REG_MULTI_SZ
    ' Remarks:
    '==========================================================
    Public Function fWSHGetRegKey(STRNAME As String, vValue As Variant) As Long
        vValue = objWSH.RegRead(STRNAME)
        
        If Err.Number <> ERROR_SUCCESS Then
            fWSHGetRegKey = ERROR_CODE
        End If
    End Function
    
    
    private myCallsub()
        dim vValue as Variant
        dim LngRetValue as long
        dim strKey as String
    
        strKey =  "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Systemtray"
    
        LngRetValue  =  fWSHGetRegKey(strKey ,vValue )
    
        if LngRetValue  = ERROR_SUCCESS then
             'You can use here the readed value saved on vValue as you want.  
        end if
    
    end sub
    james

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

Featured