Hi all,
how can I read binary values from the registry (Type REG_BINARY) ?
The method ::Get from reg32.prg returns an empty string
local nValue := 0, nTyp := REG_BINARY // 3
nValue:=oReg32:Get( "test", @nTyp )
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;
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 78 guests