Results 1 to 4 of 4

Thread: Why won't this work...?! (easy...)

  1. #1

    Thread Starter
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Angry Why won't this work...?! (easy...)

    Messing around with the register. Everything's working fine, but I just can find out how to read a value... Can anyone fix this code (so that strBuf holds the value...)?
    VB Code:
    1. Dim lngResult As Long, strBuf As String
    2. strBuf = Space$(255)
    3. RegOpenKey HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProgram", lngResult
    4. RegQueryValueEx lngResult, "UninstallString", ByVal 0&, REG_SZ, ByVal strBuf, Len(strBuf)
    5. RegCloseKey lngResult
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  2. #2
    Addicted Member
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    245

    Lightbulb May i comment ....

    May be this helps...
    strBuf = Space$(255) ?
    'Try This
    strBuf = String(255, 0& )
    I may have interpret your post wrongly
    Correct me if I made a mistake...
    Hope This Helps.. .....Enjoy Coding.....//


    zak2zak

  3. #3

    Thread Starter
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: May i comment ....

    Originally posted by zak2zak
    May be this helps...
    strBuf = Space$(255) ?
    'Try This
    strBuf = String(255, 0& )
    Thanks, but it doesn't make a difference...
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  4. #4
    Addicted Member
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    245

    May i comment again?

    May be this helps....
    This is a working code......
    VB Code:
    1. Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal _
    2.     hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired _
    3.     As Long, phkResult As Long) As Long
    4. Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
    5.     (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
    6.     lpType As Long, lpData As Any, lpcbData As Long) As Long
    7. Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    8.  
    9. Public Const HKEY_CURRENT_USER = &H80000001
    10. Public Const HKEY_LOCAL_MACHINE = &H80000002
    11. Public Const HKEY_USERS = &H80000003
    12. Public Const HKEY_CURRENT_CONFIG = &H80000005
    13. Public Const HKEY_DYN_DATA = &H80000006
    14. Public Const KEY_READ = &H20019
    15. Public Const REG_SZ = 1
    16.  
    17. '--------------------------------------------------------------------
    18.  
    19. Dim lngResult As Long
    20. Dim strBuf As String
    21. Dim subkey As String
    22. Dim datatype As Long
    23. Dim slen As Long
    24. Dim retval As Long
    25.  
    26. ' Set the name of the new key and the default security settings
    27. subkey = "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProgram"
    28.  
    29. ' Create or open the registry key
    30. retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE, subkey, 0, KEY_READ, lngResult)
    31. If retval <> 0 Then
    32.     MsgBox "ERROR: Unable to open registry key!"
    33.     Exit Sub
    34. End If
    35.  
    36. strBuf = Space(255)
    37. slen = 255
    38.  
    39. retval = RegQueryValueEx(lngResult, "UninstallString", 0, datatype, ByVal strBuf, slen)
    40. If datatype = REG_SZ Then
    41.     strBuf = Left(strBuf, slen - 1)
    42.     MsgBox "UninstallString: " & strBuf
    43. Else
    44.     MsgBox "Data not in string format.  Unable to interpret data."
    45. End If
    46.  
    47. retval = RegCloseKey(lngResult)
    I may have interpret your post wrongly
    Correct me if I made a mistake...
    Hope This Helps.. .....Enjoy Coding.....//


    zak2zak

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