'This is the code i have so far:
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 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
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias _
"RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal _
lpValueName As String, lpcbValueName As Long, ByVal lpReserved As _
Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Const REG_SZ = 1 ' Unicode nul terminated String
Private Const REG_EXPAND_SZ = 2
Private Const REG_DWORD = 4 ' 32-bit number
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 REG_BINARY = 3
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
Private Function SaveString(hKey As Long, strPath As String, strValue As
String, strdata As String) As Long
Dim keyhandle As Long
Dim r As Long
Dim lngRet As Long
r = RegCreateKey(hKey, strPath, keyhandle)
lngRet = RegSetValueEx(keyhandle, strValue, 0, REG_BINARY, ByVal strdata,
Len(strdata))
r = RegCloseKey(keyhandle)
SaveString = lngRet
End Function
Private Function Get_Value() As String
Get_Value = GetString(HKEY_LOCAL_MACHINE, "SYSTEM\x", "key")
End Function
Private Function Set_Value(ByVal strValue As String)
Dim a As Long
a = SaveString(HKEY_LOCAL_MACHINE, "SYSTEM\x", "key", strValue)
SaveString HKEY_LOCAL_MACHINE, "SYSTEM\x", "key", strValue
End Function
Public Function GetString(hKey As Long, strPath As String, strValue As
String)
Dim KeyHand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
Dim r As Long
Dim lValueType As Long
r = RegOpenKey(hKey, strPath, KeyHand)
lResult = RegQueryValueEx(KeyHand, strValue, 0&, lValueType, ByVal 0&,
lDataBufSize)
If lValueType = REG_BINARY Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(KeyHand, strValue, 0&, 0&, ByVal strBuf,
lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
GetString = Left(strBuf, intZeroPos - 1)
Else
GetString = strBuf
End If
End If
End If
End Function
Private Sub Command1_Click()
Text1 = Get_Value
End Sub
Private Sub Command2_Click()
Set_Value (Text2)
End Sub
'Unfortuneatly, although it edits the proper binary key, the string you
enter into text2 does not match the data in the key. Entering a "0" really
enters "30". I need the key to be "01 00 00 00".