ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Reading and Writing Registry Values with Visual Basic
Subject:   Writing DWORD values to the registry
Date:   2007-02-16 16:29:19
From:   Bomber686
Hi,


I'm having trouble writing to the registry when try to use dword values. I've played with changing the data type of both the value in the DIM and in the function. I'm well stuck can anyone assist? Here's the code I have -



'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()
' Create a REG_DWORD value
Dim dword As Long
dword = 2
RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey
sValueName = "SandBox"


RegSetValueEx nBufferKey, sValueName, 0, REG_DWORD, dword, Len(dword)
'nVal = 2
'If RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey) = ERROR_SUCCESS Then
' RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, nVal, Len(nVal)
'End If
'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


As you can see I've been playing but no good. Either the value is not right in the registry or is an invalid dword value. All I want to do is write the value as 2. But I can't run this using WMI code.