0

Hi all,

I have this code

Option Explicit
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 RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_DWORD = 4
Dim nBufferKey As Long
Dim nVal As Long

Private Sub Form_Load()
    nVal = 2
    RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey
    RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, nVal, Len(nVal)
    'MsgBox "Sandbox Mode Changed", vbInformation, "Sandbox"
    RegCloseKey nBufferKey
    Unload Me
End Sub

All I am try to do is write a DWORD value of 2 to the registry. The above code does work without error but the key has a value of 32(50), if I change nVal to 0 the key reads 30(48). I know that the RegSetValueEx function is expecting nVal to be a string but if I declare nVal as a string then the SandBoxMode DWORD value becomes an "Invalid DWORD value". Can anyone assist in getting the key to read 2.

1
Contributor
1
Reply
3
Views
10 Years
Discussion Span
Last Post by Bomber686
0

I found it.... Turns out you declare the function different

Option Explicit
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 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 Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_DWORD = 4
Dim nBufferKey As Long
Dim nVal As Long
Private Sub Form_Load()
    nVal = 2
    RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey
    RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, nVal, Len(nVal)
    MsgBox "Sandbox Mode Changed", vbInformation, "Sandbox"
    RegCloseKey nBufferKey
    Unload Me
End Sub

Works now, hope this is useful

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.