Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

how can i change registry value from vb

Last post 07-22-2008 8:12 AM by depash. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-18-2008 6:24 AM

    how can i change registry value from vb

     Please help

    how can i change registry value from vb , and how can i write new registry value from vb .

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 07-18-2008 10:34 AM In reply to

    • Jugatsu
    • Top 500 Contributor
    • Joined on 02-15-2006
    • Addicted Member
    • Points 485

    Re: how can i change registry value from vb

    You can use SaveSetting
    SaveSetting App.Title, "Form Location", "Left", "250"
    and GetSetting to read it back.

    If it is a specific key you want to write you have to use Windows API
    Here's a module to get you started
    http://pscode.com/vb/scripts/ShowCode.asp?txtCodeId=10479&lngWId=1

    It's easier in VB.NET

    • Post Points: 10
  • 07-18-2008 7:35 PM In reply to

    • depash
    • Not Ranked
    • Joined on 07-08-2008
    • France
    • New Member
    • Points 65

    Re: how can i change registry value from vb

     What if you want to create a key in the HKEY_LOCAL_MACHINE as opposed to HKEY_CURRENT_USER?

    Is it posible to store a value and retrieve within this section.

    • Post Points: 10
  • 07-21-2008 3:33 PM In reply to

    Re: how can i change registry value from vb

    declare the api functions e.g. below :-

    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private 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
    Private 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
    Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long

     create a simple function to call api's e.g. below :-

    Public Function GetSettingString(hKey As hndKey, _
                                     strPath As String, _
                                     strValue As String, _
                                     Optional Default As String) As String

        Dim hCurKey As Long
        Dim lResult As Long
        Dim lValueType As Long
        Dim strBuffer As String
        Dim lDataBufferSize As Long
        Dim intZeroPos As Integer
        Dim lRegResult As Long
       
        lRegResult = RegOpenKey(hKey, strPath, hCurKey)
        lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, lValueType, ByVal 0&, lDataBufferSize)
       
        If lRegResult = ERROR_SUCCESS Then
            If lValueType = REG_SZ Then
                strBuffer = String(lDataBufferSize, " ")
            lResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, ByVal strBuffer, lDataBufferSize)
            intZeroPos = InStr(strBuffer, Chr$(0))
                If intZeroPos > 0 Then
                    GetSettingString = left$(strBuffer, intZeroPos - 1)
                Else
                    GetSettingString = strBuffer
                End If
            End If
        Else
            If Default = "" Then
                GetSettingString = ""
            ElseIf (Default = "Initial") Then
                GetSettingString = "NoValues"
            Else
                GetSettingString = Default
                SaveSettingString hKey, strPath, strValue, Default
            End If
        End If
           
        lRegResult = RegCloseKey(hCurKey)

    End Function

     finally call you new function

    GetSettingString(HKEY_LOCAL_MACHINE, "any subordinate path goes here", "string name")

    • Post Points: 10
  • 07-22-2008 8:12 AM In reply to

    • depash
    • Not Ranked
    • Joined on 07-08-2008
    • France
    • New Member
    • Points 65

    Re: how can i change registry value from vb

     Thanks for this wonderful code bro, but am abit of a leaner in vb, could you please help me with the statement for saving a value in this function and also retrieving a value form this key, please i will be grateful

    • Post Points: 5
Page 1 of 1 (5 items)