Results 1 to 8 of 8

Thread: Grrr...Stupid registry...

  1. #1

    Thread Starter
    Member Cahlel's Avatar
    Join Date
    Aug 2000
    Location
    Earth (I think)
    Posts
    63

    Angry

    Grrrr... I can't get this code to work:

    Private Sub Command1_Click()
    textvalue = GetSetting(HKEY_CURRENT_USER, "Control Panel\desktop", "ScreenSave_Data", "")
    Text1.Text = textvalue
    End Sub

    I get a stupid error, all I want is the text value of the key! Help please...
    Wisdom is supreme, therefore get wisdom,
    though it costs all you have, get understanding.
    Proverbs 4:7

  2. #2
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    Have you tried putting quotation marks around the AppName

    ie:
    Code:
    textvalue = GetSetting("HKEY_CURRENT_USER", "ControlPanel\desktop", "ScreenSave_Data", "")
    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  3. #3

    Thread Starter
    Member Cahlel's Avatar
    Join Date
    Aug 2000
    Location
    Earth (I think)
    Posts
    63

    Unhappy Well....

    Well, I tried that, and I'm supposed to get something like :
    10 32 45 43 67 54 34 34 23...etc...
    but all I get is blank text, no text. ????
    Wisdom is supreme, therefore get wisdom,
    though it costs all you have, get understanding.
    Proverbs 4:7

  4. #4
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi Cahlel,
    Sorry, I should have looked into it more

    Visual Basic provides a standard registry location for storing program information for applications created in Visual Basic:

    HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appname\section\key

    from MSDN
    Basically with GetSetting you can only access registry keys within this path. To get others you will have to call the API. Not sure how to do that so maybe someone else will help you.

    Shaun

    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The GetSetting function start to read from HKEY_CURRENT_USER\Software\VB and VBA program settings
    It can't read from any other place. If you want to read from somewhere else in the Registry you have to sort to the API. Read this article

    Good luck!

  6. #6
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754

    Wink

    go to BlackBeltVB.Com and do a search on "Registry" and download the sample. The Getsetting function is for retrieving application data, not system values. see the following excerpt from MSDN:

    Visual Basic provides a standard registry location for storing program information for applications created in Visual Basic:

    HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appname\section\key

    Visual Basic also provides four statements and functions to manipulate the settings stored in your application's registry location.

    Function or Statement Description
    GetSetting function Retrieves registry settings.
    SaveSetting statement Saves or creates registry settings.
    GetAllSettings function Returns an array containing multiple registry settings.
    DeleteSetting statement Deletes registry settings.

    Hope this Helps

    Crispin




  7. #7
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Megatron's code:

    Code:
    'Module
    
    Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Long) As Long
    Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String) As Long
    Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal HKEY As Long, ByVal lpValueName As String) As Long
    Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    Public Const HKEY_CLASSES_ROOT = &H80000000
    Public Const HKEY_CURRENT_USER = &H80000001
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const HKEY_USERS = &H80000003
    Public Const HKEY_PERFORMANCE_DATA = &H80000004
    Public Const REG_SZ = 1
    
    Function RegQueryStringValue(ByVal HKEY As Long, ByVal strValueName As String)
        Dim lResult As Long
        Dim lValueType As Long
        Dim strBuf As String
        Dim lDataBufSize As Long
        
        On Error GoTo 0
        lResult = RegQueryValueEx(HKEY, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
        If lResult = ERROR_SUCCESS Then
            If lValueType = REG_SZ Then
                strBuf = String(lDataBufSize, " ")
                lResult = RegQueryValueEx(HKEY, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
                If lResult = ERROR_SUCCESS Then
                    RegQueryStringValue = StripTerminator(strBuf)
                End If
            End If
        End If
    End Function
    
    Public Function GetSettingEx(HKEY As Long, sPath As String, sValue As String)
        Dim KeyHand&
        Dim datatype&
        Call RegOpenKey(HKEY, sPath, KeyHand&)
        GetSettingEx = RegQueryStringValue(KeyHand&, sValue)
        Call RegCloseKey(KeyHand&)
    End Function
    
    Function StripTerminator(ByVal strString As String) As String
        Dim intZeroPos As Integer
    
        intZeroPos = InStr(strString, Chr$(0))
        If intZeroPos > 0 Then
            StripTerminator = Left$(strString, intZeroPos - 1)
        Else
            StripTerminator = strString
        End If
    End Function
    
    Public Sub SaveSettingEx(HKEY As Long, sPath As String, sValue As String, sData As String)
        Dim KeyHand As Long
        Call RegCreateKey(HKEY, sPath, KeyHand)
        Call RegSetValueEx(KeyHand&, sValue, 0, REG_SZ, ByVal sData, Len(sData))
        Call RegCloseKey(KeyHand&)
    End Sub
    Usage: Needs 2 Commandbuttons

    Code:
    Private Sub Command1_Click()
        'Save a value to the Registry
        SaveSettingEx HKEY_CURRENT_USER, "Software\Myapp", "Testing", "Hello"
    End Sub
    
    Private Sub Command2_Click()
        'Get a value from the Registry
        Retval = GetSettingEx(HKEY_CURRENT_USER, "Software\MyApp", "Testing")
        Print Retval
    End Sub
    Courgettes.

  8. #8
    Guest
    If you would like to save in different formats (i.e DWORD), simply replace REG_SZ with with REG_DWORD or whatever format you want.

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