-
Hello all!
I am trying to find out what is the best way to write binary (REG_BINARY) type values to the registry.
Say I have the following: 42, 41, 42, 41, 00, 31, 45, 46, 45, 00 (= BABA.1EFE.) and I would like to write all of that to the registry for a REG_BINARY type value.
Any ideas?? Any help would be GREATLY appreciated.
-
Use RegSetValueEx
Code:
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 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
Const HKEY_CURRENT_USER = &H80000001
Const REG_BINARY = 3
Sub SaveSettingEx(HKEY As Long, sPath As String, sValue As String, sData As String)
Dim KeyHand As Long
Call RegCreateKey(HKEY, sPath, KeyHand)
Call RegSetValueEx(KeyHand&, sValue, 0, REG_BINARY, ByVal sData, Len(sData))
Call RegCloseKey(KeyHand&)
End Sub
Private Sub Command1_Click()
SaveSettingEx HKEY_CURRENT_USER, "Software\BinaryTesting", "BinaryValue", "BABA.1EFE"
End Sub
-
It worked!!
Thanks a whole bunch.