How do I write binary keys to the registry?
Moderator: Rathinagiri
How do I write binary keys to the registry?
I have an application that needs to write binary keys to the registry.
If I should be in
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU] writes the following data:
"a"=hex:6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,00,\
00,44,00,3a,00,5c,00,44,00,45,00,56,00,5c,00,53,00,63,00,72,00,69,00,70,00,\
74,00,45,00,64,00,69,00,74,00,5c,00,56,00,42,00,53,00,45,00,64,00,69,00,74,\
00,5c,00,56,00,42,00,53,00,00,00
How do I implement them?
Thanks in advance.
If I should be in
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU] writes the following data:
"a"=hex:6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,00,\
00,44,00,3a,00,5c,00,44,00,45,00,56,00,5c,00,53,00,63,00,72,00,69,00,70,00,\
74,00,45,00,64,00,69,00,74,00,5c,00,56,00,42,00,53,00,45,00,64,00,69,00,74,\
00,5c,00,56,00,42,00,53,00,00,00
How do I implement them?
Thanks in advance.
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
- Has thanked: 100 times
- Been thanked: 179 times
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- andyglezl
- Posts: 911
- Joined: Fri Oct 26, 2012 7:58 pm
- Location: Guadalajara Jalisco, MX
- Has thanked: 7 times
- Been thanked: 32 times
- Contact:
Hola Huiyi_ch
Ya probaste con estas funciones ?
Modificar el Registro es de cuidado. . .
------------------------------------------------------
Hi Huiyi_ch
Already tried with these functions?
Modifying the Registry is for care. . .
Functions.RegistryRead: Reads Registry Data
Functions.RegistryWrite: Writes Data To System Registry
RegistryRead( cRegPath )
RegistryWrite( cRegPath , xValue )
Ya probaste con estas funciones ?
Modificar el Registro es de cuidado. . .
------------------------------------------------------
Hi Huiyi_ch
Already tried with these functions?
Modifying the Registry is for care. . .
Functions.RegistryRead: Reads Registry Data
Functions.RegistryWrite: Writes Data To System Registry
RegistryRead( cRegPath )
RegistryWrite( cRegPath , xValue )
Andrés González López
Desde Guadalajara, Jalisco. México.
Desde Guadalajara, Jalisco. México.
您好,Pablo CésarPablo César wrote: ↑Wed May 17, 2017 11:50 amHi Huiyi,
In your place I would make in VBS.
http://stackoverflow.com/questions/2833 ... gistry-key
非常感谢您的帮助.是否可以写一个能写入二进制数据的注册表函数呢?
Hello Pablo César
Thank you very much for your help. Can you write a registry function that can write binary data?
您好andyglezlandyglezl wrote: ↑Wed May 17, 2017 2:16 pmHola Huiyi_ch
Ya probaste con estas funciones ?
Modificar el Registro es de cuidado. . .
------------------------------------------------------
Hi Huiyi_ch
Already tried with these functions?
Modifying the Registry is for care. . .
Functions.RegistryRead: Reads Registry Data
Functions.RegistryWrite: Writes Data To System Registry
RegistryRead( cRegPath )
RegistryWrite( cRegPath , xValue )
这些函数我已试过了,好象不能将二进制数据写入注册表.
Hi andyglezl
I have tried this function, as if I could not write binary data into the registry
-
- Posts: 285
- Joined: Thu Oct 16, 2014 11:35 am
- Location: Poland
- Has thanked: 76 times
- Been thanked: 225 times
Hi huiyi_ch.huiyi_ch wrote: ↑Wed May 17, 2017 4:58 amI have an application that needs to write binary keys to the registry.
If I should be in
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU] writes the following data:
"a"=hex:6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,00,\
00,44,00,3a,00,5c,00,44,00,45,00,56,00,5c,00,53,00,63,00,72,00,69,00,70,00,\
74,00,45,00,64,00,69,00,74,00,5c,00,56,00,42,00,53,00,45,00,64,00,69,00,74,\
00,5c,00,56,00,42,00,53,00,00,00
How do I implement them?
Thanks in advance.
There is a bug in win_reg.prg in Harbour sources that prevents the registry from writing values in binary data.
I modified it by adding an array support with binary data or a binary string.
It seems to me that it should solve your problem.
Kindest regards, Edward.
Code: Select all
#include "hmg.ch"
#include "hbwin.ch"
*********************************************
PROCEDURE Main()
Local nByte
//binary array
aReg := {0x6e,0x00,0x6f,0x00,0x74,0x00,0x65,0x00,0x70,0x00,0x61,0x00,0x64,0x00,0x2e,0x00,0x65,0x00,0x78,0x00,0x65,0x00,0x00,;
x00,0x44,0x00,0x3a,0x00,0x5c,0x00,0x44,0x00,0x45,0x00,0x56,0x00,0x5c,0x00,0x53,0x00,0x63,0x00,0x72,0x00,0x69,0x00,0x70,0x00,;
x74,0x00,0x45,0x00,0x64,0x00,0x69,0x00,0x74,0x00,0x5c,0x00,0x56,0x00,0x42,0x00,0x53,0x00,0x45,0x00,0x64,0x00,0x69,0x00,0x74,;
0x00,0x5c,0x00,0x56,0x00,0x42,0x00,0x53,0x00,0x00,0x00}
//binary string
cReg:=""
FOR EACH nByte IN aReg
cReg := cReg + Chr(nByte)
NEXT
//writing registry value as binary array
MsgInfo( win_regWrite2( "HKCU\_TEST\a", aReg, WIN_REG_BINARY ) , 'Binary Array')
//writing registry value as binary string
MsgInfo( win_regWrite2( "HKCU\_TEST\c", cReg, WIN_REG_BINARY ) , 'Binary String')
QUIT
RETURN
***********************************************************************
FUNCTION win_regWrite2( cRegPath, xValue, nType, nRegSam )
LOCAL nHKEY, cKey, cEntry
win_regPathSplit( cRegPath, @nHKEY, @cKey, @cEntry )
RETURN win_regSet2( nHKEY, cKey, cEntry, xValue, nType, nRegSam )
*************************************************************
FUNCTION win_regSet2( nHKEY, cKeyName, cEntryName, xValue, nValueType, nRegSam )
LOCAL cName
LOCAL lRetVal := .F.
LOCAL pKeyHandle
LOCAL nByte
hb_default( @nRegSam, 0 )
IF win_regCreateKeyEx( nHKEY, cKeyName, 0, 0, 0, hb_bitOr( KEY_SET_VALUE, nRegSam ), 0, @pKeyHandle )
/* no support for Arrays, Codeblock ... */
SWITCH ValType( xValue )
CASE "A" //added support for array of binary
IF ! HB_ISNUMERIC( nValueType ) .OR. !(nValueType == WIN_REG_BINARY)
cName := Nil
ELSE
cName := ''
FOR EACH nByte IN xValue
cName := cName + Chr(nByte)
NEXT
ENDIF
EXIT
CASE "L"
nValueType := WIN_REG_DWORD
cName := iif( xValue, 1, 0 )
EXIT
CASE "D"
nValueType := WIN_REG_SZ
cName := DToS( xValue )
EXIT
CASE "N"
IF ! HB_ISNUMERIC( nValueType ) .OR. ;
!( nValueType == WIN_REG_DWORD .OR. ;
nValueType == WIN_REG_DWORD_LITTLE_ENDIAN .OR. ;
nValueType == WIN_REG_DWORD_BIG_ENDIAN .OR. ;
nValueType == WIN_REG_QWORD .OR. ;
nValueType == WIN_REG_QWORD_LITTLE_ENDIAN )
nValueType := WIN_REG_DWORD
ENDIF
cName := xValue
EXIT
CASE "C"
CASE "M"
//added support for string of binary
IF ! HB_ISNUMERIC( nValueType ) .OR. ;
!( nValueType == WIN_REG_SZ .OR. ;
nValueType == WIN_REG_EXPAND_SZ .OR. ;
nValueType == WIN_REG_BINARY .OR. ;
nValueType == WIN_REG_MULTI_SZ )
nValueType := WIN_REG_SZ
ENDIF
cName := xValue
EXIT
ENDSWITCH
IF cName != NIL
lRetVal := win_regSetValueEx( pKeyHandle, cEntryName, 0, nValueType, cName )
ENDIF
win_regCloseKey( pKeyHandle )
ENDIF
RETURN lRetVal
****** END ******************
- Attachments
-
- reg_binary.7z
- (1.11 MiB) Downloaded 58 times
-
- Posts: 285
- Joined: Thu Oct 16, 2014 11:35 am
- Location: Poland
- Has thanked: 76 times
- Been thanked: 225 times
Just convert each character from string into ascii value ASC() and put to array.
Code: Select all
Local aBin := {}
Local c1Chr
FOR EACH c1Chr IN cStringBin
AADD( aBin, ASC(c1Chr))
NEXT