473,490 Members | 2,695 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 9646

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1961
by: Pat Blair | last post by:
Sorry to anyone who read this post, but in case it's useful to anyone: Further experiments reveal that while a tuple comes back if you read a multi-line string, you set the value using a list (not...
1
1645
by: Jim Moon | last post by:
I'm setting up a Win Server 2003 for remote debugging. From this page, I see that I need to set two registry keys on the server:...
0
7679
by: DJP | last post by:
Hi there I need to be able to programmatically set permissions on registry keys using VB / VBScript / VBA. So far I have had a look at doing this using the WScript.Shell object, API calls, and...
6
1467
by: Gustaf | last post by:
My Windows app is dependant on some registry keys settings. In case the subkey for the app doesn't exists, I want to show a messagebox, and then quit the whole program (without showing the main...
2
1696
by: jphelan | last post by:
I was testing the install and uninstall, on my WindowsXP Pro SP2 machine, of software that I created, called, "inbusiness". Because of the following error message that I received on attempting to...
5
6956
by: Sin Jeong-hun | last post by:
I need to read some registry keys of a remote computer. The key will be any key users provide. (For example : HKEY_CURRENT_USER\SOFTWARE \MyGame) I found that there was a handy method called...
1
1254
by: John | last post by:
Hi How does one set registry keys in a set-up project? Would these keys come off on uninstall? Thanks Regards
0
4603
by: Gary | last post by:
I'm having trouble entering Additional Registry Keys into my Package Solution that will deploy the Access 2007 runtime. (Client machine is running XP with Office 2007 Standard.) The Package...
0
1837
by: diego72 | last post by:
Hi!, I'm trying to delete some registry keys and subkeys with a vbs script, deploying it through gpo starup script. The Os is Windows 2003 Enterprise Server R2 and the clients are Windows Xp. The...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.