Read binary values from registry
-
- Posts: 824
- Joined: Thu Oct 13, 2005 7:39 am
- Location: Germany
Read binary values from registry
Hi all,
how can I read binary values from the registry (Type REG_BINARY) ?
The method ::Get from reg32.prg returns an empty string
how can I read binary values from the registry (Type REG_BINARY) ?
The method ::Get from reg32.prg returns an empty string
kind regards
Stefan
Stefan
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
-
- Posts: 824
- Joined: Thu Oct 13, 2005 7:39 am
- Location: Germany
Antonio,
I tried this
nValue and nTyp have both the value of 3
Normally it should return an array of hex values
I tried this
Code: Select all
local nValue := 0, nTyp := REG_BINARY // 3
nValue:=oReg32:Get( "test", @nTyp )
Normally it should return an array of hex values
kind regards
Stefan
Stefan
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Stefan,
Please try this new method:
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
-
- Posts: 824
- Joined: Thu Oct 13, 2005 7:39 am
- Location: Germany
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++
c#
Maybe these functions are helpful for you
[/quote]
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;
}
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;
[/quote]
kind regards
Stefan
Stefan
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
-
- Posts: 824
- Joined: Thu Oct 13, 2005 7:39 am
- Location: Germany
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
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
kind regards
Stefan
Stefan
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact: