473,796 Members | 2,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Editing binary registry keys

'This is the code i have so far:

Private Declare Function RegCloseKey Lib "advapi32.d ll" (ByVal hKey As _
Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.d ll" Alias _
"RegOpenKey A" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult _
As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.d ll" Alias _
"RegQueryValueE xA" (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.d ll" Alias _
"RegEnumVal ueA" (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_RO OT = &H80000000
Private Const HKEY_CURRENT_US ER = &H80000001
Private Const HKEY_LOCAL_MACH INE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const REG_BINARY = 3

Private Declare Function RegCreateKey Lib "advapi32.d ll" Alias _
"RegCreateK eyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.d ll" 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(hK ey, strPath, keyhandle)
lngRet = RegSetValueEx(k eyhandle, strValue, 0, REG_BINARY, ByVal strdata,
Len(strdata))
r = RegCloseKey(key handle)
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_MACH INE, "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(lDataBuf Size, " ")
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 9678

"Jester" <ch******@comca st.net> wrote in message
news:ub******** ************@co mcast.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*****@Intell igenCIA.com> wrote in message
news:1f******** ****@nwrdny01.g nilink.net...

"Jester" <ch******@comca st.net> wrote in message
news:ub******** ************@co mcast.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*****@Intell igenCIA.com> wrote in message
news:1f******** ****@nwrdny01.g nilink.net...

"Jester" <ch******@comca st.net> wrote in message
news:ub******** ************@co mcast.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
1982
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 a tuple). That's sensible and I don't know why this didn't occur to me before I posted. Thanks -----Original Message----- From: Pat Blair
1
1675
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vctskinstallingremotedebugmonitor.asp This key already exists: with: Name: (Default) Type: REG_SZ
0
7695
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 WMI but the only one of these that goes any where near registry permissions is WMI and that is only to get the permissions of a key (cannot set). I am also quite happy for the code to call an external program to perform the task but can't seem to...
6
1481
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 form). How do you accomplish this? The program starts with: static void Main() {
2
1725
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 uninstall the program through, "Add/Remove", I assume that I will have to find some other way to remove it. "An installation package for the product InBusiness for - Nonprofits cannot be found. Try the installation again using a valid copy of...
5
6976
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 RegistryKey.OpenRemoteBaseKey(); I tried But everytime I execute it, an UnauthorizedAccessException occurred at the OpenRemoteBaseKey method. Both computer (the one that ran the C# application, and the remote computer) are Windows XP Professional,...
1
1273
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
4642
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 Solution Wizard, on about page 3, has a section for entering Additional Registry Keys. I want to include a locations key that will identify my install directory as a Trusted Location, thereby turning off the Security Alert when users open the ACCDR. ...
0
1853
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 problem is that, although I run the script perfectly in local double-clicking it, when the script is deployed via gpo, registry keys remain undeleted. I've used several echos to know it if was being executed and it was, but keys remained there. ...
0
9525
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10169
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9050
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.