469,289 Members | 2,330 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

Editing binary registry keys

'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".
Jul 17 '05 #1
3 9273

"Jester" <ch******@comcast.net> wrote in message
news:ub********************@comcast.com...
'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".


The ASCII text "0" is 48. In hexadecimal it is 30. So it is doing what it
suppose to do.
If you want to write hex 00, you need to write CHR$(0)
Jul 17 '05 #2

"Raoul Watson" <Wa*****@IntelligenCIA.com> wrote in message
news:1f************@nwrdny01.gnilink.net...

"Jester" <ch******@comcast.net> wrote in message
news:ub********************@comcast.com...
'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".


The ASCII text "0" is 48. In hexadecimal it is 30. So it is doing what it
suppose to do.
If you want to write hex 00, you need to write CHR$(0)

i knew it was doing what it was supposed to, its just that i was trying to
circumvent how it does it. Thanks for the CHR$(0) tip, i'll try it out, and
let you know if it works.
Jul 17 '05 #3

"Raoul Watson" <Wa*****@IntelligenCIA.com> wrote in message
news:1f************@nwrdny01.gnilink.net...

"Jester" <ch******@comcast.net> wrote in message
news:ub********************@comcast.com...
'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".


The ASCII text "0" is 48. In hexadecimal it is 30. So it is doing what it
suppose to do.
If you want to write hex 00, you need to write CHR$(0)

Thanks, it works now. You're a life saver.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jim Moon | last post: by
5 posts views Thread by Sin Jeong-hun | last post: by
1 post views Thread by John | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.