Results 1 to 2 of 2

Thread: RegCreateValueEx troubles

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Posts
    140

    RegCreateValueEx troubles

    I'm having troubles with this function. Declaration:

    Code:
    Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
    With the phkResult As Long, what am I supposed to put there? I've looked and can't find what kind of information goes there. I tried a Long var and I got an error. I tried 0& and I got an error, I tried ByVal 0& and got an error. What goes there? Please help.
    -Nean

  2. #2
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613
    Code:
    Const HKEY_CURRENT_USER = &H80000001
    Const REG_OPTION_BACKUP_RESTORE = 4     ' open for backup or restore
    Const REG_OPTION_VOLATILE = 1           ' Key is not preserved when system is rebooted
    Const REG_OPTION_NON_VOLATILE = 0       ' Key is preserved when system is rebooted
    Const STANDARD_RIGHTS_ALL = &H1F0000
    Const SYNCHRONIZE = &H100000
    Const READ_CONTROL = &H20000
    Const STANDARD_RIGHTS_READ = (READ_CONTROL)
    Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
    Const KEY_CREATE_LINK = &H20
    Const KEY_CREATE_SUB_KEY = &H4
    Const KEY_ENUMERATE_SUB_KEYS = &H8
    Const KEY_NOTIFY = &H10
    Const KEY_QUERY_VALUE = &H1
    Const KEY_SET_VALUE = &H2
    Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
    Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
    Const KEY_EXECUTE = (KEY_READ)
    Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As Any, phkResult As Long, lpdwDisposition As Long) As Long
    Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal samDesired As Long, phkResult As Long) As Long
    Private Sub Form_Load()
        Dim Result As Long
        'Check if the specified key exists
        RegOpenKeyEx HKEY_CURRENT_USER, "MyApp", 0, KEY_ALL_ACCESS, Result
        If Result = 0 Then
            'Create a new key
            RegCreateKeyEx HKEY_CURRENT_USER, "MyApp", 0, "REG_DWORD", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, ByVal 0&, Result, Ret
            If Result = 0 Then
                MsgBox "Error while creating the Key!!"
                Exit Sub
            End If
        End If
        'Delete the key
        RegDeleteKey Result, ""
        'close the handle
        RegCloseKey Result
    End Sub

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