Page 1 of 1
Read binary values from registry
Posted: Mon Jul 07, 2008 9:20 pm
by StefanHaupt
Hi all,
how can I read binary values from the registry (Type REG_BINARY) ?
The method ::Get from reg32.prg returns an empty string
Posted: Tue Jul 08, 2008 1:40 pm
by Antonio Linares
Stefan,
Have you supplied a second parameter with numeric type ?
local nValue := 0
oReg32:Get( "test", @nValue )
or
nValue = oReg32:Get( "test", 0 )
Posted: Wed Jul 09, 2008 10:55 am
by StefanHaupt
Antonio,
I tried this
Code: Select all
local nValue := 0, nTyp := REG_BINARY // 3
nValue:=oReg32:Get( "test", @nTyp )
nValue and nTyp have both the value of 3
Normally it should return an array of hex values
Posted: Wed Jul 09, 2008 11:08 pm
by Antonio Linares
Stefan,
REG_BINARY is not supported in Class TReg32 yet.
We are going to implement it asap.
Posted: Thu Jul 10, 2008 1:31 am
by Antonio Linares
Stefan,
Please try this new method:
Code: Select all
METHOD GetBinary( cSubKey ) CLASS TReg32
local cBuffer, nLen := 0
::nError = RegQueryValueExA( ::nHandle, cSubkey, 0, REG_BINARY, 0, @nLen )
if ::nError == ERROR_SUCCESS
cBuffer = Space( nLen )
::nError = RegQueryValueExA( ::nHandle, cSubkey, 0, REG_BINARY, @cBuffer, @nLen )
endif
return cBuffer
Posted: Thu Jul 10, 2008 6:36 pm
by StefanHaupt
Antonio,
it returns an empty string
I found 2 functions which may work, but I could not test. One is in c++ and one is in c#. I tried to convert both in normal c, but I failed
c++
Code: Select all
#include <iostream>
#include <windows.h>
int main () {
//Zeichenvorrat Buchstaben,Ziffern ohne AEIOU01 (24)
UCHAR digits[] = {'B','C','D','F','G','H','J','K','M','P','Q','R','T','V','W','X','Y','2','3','4','6','7','8','9'};
PUCHAR strresult = new UCHAR[26];
PUCHAR buf = new UCHAR[200];
HKEY key = NULL;
DWORD datasize = 200;
DWORD dwRet = 0;
ZeroMemory((PVOID)strresult,26);
dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",0,KEY_READ,&key);
dwRet = RegQueryValueEx(key,"DigitalProductID",NULL,NULL,(LPBYTE)buf,&datasize);
if (dwRet != ERROR_SUCCESS) {
return -1;
}
RegCloseKey(key);
for (int i=24;i>=0;i--) {
int x=0;
for (int j=14;j>=0;j--) {
x = (x<<8) + (buf+0x34)[j];
(buf+0x34)[j] = x / 24;
x = x % 24;
}
strresult[i]=digits[x];
}
std::cout << strresult;
std::cin.get();
return 0;
}
c#
Code: Select all
private char[] digits = {'B','C','D','F','G','H','J','K','M','P','Q','R','T','V','W','X','Y','2','3','4','6','7','8','9'};
public string QueryRemoteKey(string remotehost) {
try {
RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,remotehost);
RegistryKey subkey = key.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
byte[] data = (byte[])subkey.GetValue("DigitalProductID");
string result = "";
for (int i=24;i>=0;i--) {
int x=0;
for (int j=14;j>=0;j--) {
x = (x<<8) + data[0x34+j];
data[0x34+j] =(byte)(x/24);
x = x%24;
}
result = result.Insert(0,digits[x].ToString());
if ( ((i%5)==0) && (i!=0) ) {
result = result.Insert(0,('-').ToString());
}
}
return result;
} catch(Exception ex) {
System.Windows.Forms.MessageBox.Show(ex.Message);
}
return String.Empty;
Maybe these functions are helpful for you
[/quote]
Posted: Thu Jul 10, 2008 7:22 pm
by Antonio Linares
Stefan,
> it returns an empty string
Try this:
MsgInfo( Len( oReg32:GetBinary( <cSubKey> ) ) )
Please let me know if the above is zero, thanks
Posted: Thu Jul 10, 2008 10:05 pm
by StefanHaupt
Antonio,
ok, problem solved, when I tried your test I got an undefined error, so I checked ::nError and it gives me an undefined handle. At last I found I had a typo in my keyname, sorry.
I just forgot a space in one name. Maybe I need new glasses
Now MsgInfo( Len( oReg32:GetBinary( <cSubKey> ) ) ) shows 164. This should be the right value.
Many thanks for your help
Posted: Thu Jul 10, 2008 10:48 pm
by Antonio Linares
Stefan,
You are welcome. We all make mistakes, fortunately we are humans and not computers
Now you can inspect the contents of the returned string using Asc( SubStr( cValue, n, 1 ) )