Read binary values from registry

Read binary values from registry

Postby StefanHaupt » Mon Jul 07, 2008 9:20 pm

Hi all,

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
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby Antonio Linares » Tue Jul 08, 2008 1:40 pm

Stefan,

Have you supplied a second parameter with numeric type ?

local nValue := 0

oReg32:Get( "test", @nValue )

or

nValue = oReg32:Get( "test", 0 )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41411
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby StefanHaupt » Wed Jul 09, 2008 10:55 am

Antonio,

I tried this
Code: Select all  Expand view
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
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby Antonio Linares » Wed Jul 09, 2008 11:08 pm

Stefan,

REG_BINARY is not supported in Class TReg32 yet.

We are going to implement it asap.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41411
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Thu Jul 10, 2008 1:31 am

Stefan,

Please try this new method:
Code: Select all  Expand view
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     
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41411
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby StefanHaupt » Thu Jul 10, 2008 6:36 pm

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  Expand view
#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  Expand view
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]
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby Antonio Linares » Thu Jul 10, 2008 7:22 pm

Stefan,

> it returns an empty string

Try this:

MsgInfo( Len( oReg32:GetBinary( <cSubKey> ) ) )

Please let me know if the above is zero, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41411
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby StefanHaupt » Thu Jul 10, 2008 10:05 pm

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. :oops: I just forgot a space in one name. Maybe I need new glasses :wink:

Now MsgInfo( Len( oReg32:GetBinary( <cSubKey> ) ) ) shows 164. This should be the right value.

Many thanks for your help :D
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby Antonio Linares » Thu Jul 10, 2008 10:48 pm

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 ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41411
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 46 guests