Results 1 to 2 of 2

Thread: Rename A Registry Key

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    1

    Red face

    Hello,
    I am looking for anyone who can help me to Rename an existing registry key. Suppose, I create a new Key and I mispell the name of the Key, then I would like to rename this Key name. How can I do that?
    I am using VB6 to access registry key. Please help me.
    Thank you.


    [Edited by sadhat on 09-11-2000 at 01:53 PM]

  2. #2
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Code:
    Private Const HKEY_CLASSES_ROOT = &H80000000
    Private Const HKEY_CURRENT_USER = &H80000001
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const HKEY_USERS = &H80000003
    Private Const HKEY_CURRENT_CONFIG = &H80000005
    Private Const HKEY_DYN_DATA = &H80000006
    Private Const REG_SZ = 1
    Private Const REG_BINARY = 3
    Private Const REG_DWORD = 4
    Private Const ERROR_SUCCESS = 0&
    
    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 RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) 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 RegCloseKey Lib "advapi32.dll" (ByVal Hkey 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
    
    Public Sub savestring(Hkey As Long, strPath As String, strValue As String, strdata As String)
        Dim keyhand As Long
        Dim r As Long
        r = RegCreateKey(Hkey, strPath, keyhand)
        r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
        r = RegCloseKey(keyhand)
    End Sub
    
    Public Sub Command1_Click()
    'This will rename the username string to whatever is in the Textbox
    Call savestring(HKEY_LOCAL_MACHINE, "Network\Logon", "username", Text1.Text)
    End Sub
    Hope that helps,
    D!m
    Dim

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