Hi all,
how can I read binary values from the registry (Type REG_BINARY) ?
The method ::Get from reg32.prg returns an empty string
Stefan
Hi all,
how can I read binary values from the registry (Type REG_BINARY) ?
The method ::Get from reg32.prg returns an empty string
Stefan,
Have you supplied a second parameter with numeric type ?
local nValue := 0
oReg32:Get( "test", @nValue )
or
nValue = oReg32:Get( "test", 0 )
local nValue := 0, nTyp := REG_BINARY // 3
nValue:=oReg32:Get( "test", @nTyp )Stefan,
REG_BINARY is not supported in Class TReg32 yet.
We are going to implement it asap.
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#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;
}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;Stefan,
> it returns an empty string
Try this:
MsgInfo( Len( oReg32:GetBinary( <cSubKey> ) ) )
Please let me know if the above is zero, thanks
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 ![]()
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 ) )