mol wrote:I thought I've solved this problem

When I was working on windows XP, everything was going OK, on my home computer (w7 prof) -OK, on the client side - win7 home premium - problems with rights. Client hadn't admin rights.
But, maybe you will find any idea...
Hi Marek, me again...
I have found half of way gone... with:
SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\PORTS works OK, in XP, Win7 (with and without special rights)
but... with:
HARDWARE\DEVICEMAP\SERIALCOMM is getting keys names but not with its Values...
I have read this:
Note that the backslash character is, as mentioned, used by QSettings to separate subkeys. As a result, you cannot read or write windows registry entries that contain slashes or backslashes; you should use a native windows API if you need to do so.
So, I do not find the right way to extract Valued of each keys...
Anyway, see this code probably will helps you...
Code: Select all
/* HMG 3.1.5 */
#include <hmg.ch>
#define HKEY_CLASSES_ROOT 2147483648
#define HKEY_CURRENT_USER 2147483649
#define HKEY_LOCAL_MACHINE 2147483650
#define HKEY_USERS 2147483651
#define HKEY_PERFORMANCE_DATA 2147483652
#define HKEY_CURRENT_CONFIG 2147483653
#define HKEY_DYN_DATA 2147483654
#define ERROR_SUCCESS 0
Function Main()
Local aReg
aReg := EnumValues( HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE", "SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\PORTS\" )
MsgDebug1("CURRENTVERSION\PORTS",aReg)
aReg := EnumValues( HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE", "HARDWARE\DEVICEMAP\SERIALCOMM" )
MsgDebug1("DEVICEMAP\SERIALCOMM",aReg)
/*
aReg := EnumKeys( HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE", "SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\" )
MsgDebug(aReg)
*/
Return Nil
Function EnumValues(nKey,cKey,cSubKey)
Local hKey, cName, uValue, n := 0, aRet:={}
RegOpenKey( nKey, cSubKey, @hKey )
Do While RegEnumValue( hKey, n++, @cName, @uValue ) == ERROR_SUCCESS
AAdd(aRet,{cName, RegistryRead(cKey+"\"+cSubKey+cName)})
// AAdd(aRet,{cName, RegQueryValueExW(cKey+"\"+cSubKey+cName)})
Enddo
RegCloseKey( hKey )
Return aRet
Function EnumKeys(nKey,cKey,cSubKey)
Local hKey, cName, n := 0, aRet:={}
RegOpenKey( nKey, cSubKey, @hKey )
Do While RegEnumKeyExW( hKey, n++, @cName ) == ERROR_SUCCESS
AAdd(aRet,cName)
Enddo
RegCloseKey( hKey )
Return aRet
Function MsgDebug1
Local i, cMsg, nParam:=PCOUNT(), nStart:=1, cTit:="DEBUG INFO"
If nParam>1 .and. ValType(PValue(1))="C"
nStart:=2
cTit:=PValue(1)
Endif
cMsg := "Called from: " + ProcName(1) + "(" + LTrim(Str(ProcLine(1))) + ") --> " + ProcFile(1) + CRLF + CRLF
For i = nStart To nParam
cMsg := cMsg + hb_ValToExp(PValue(i)) + IIf (i < nParam, ", ", "")
Next
MsgBox(cMsg, cTit)
Return cMsg
#pragma BEGINDUMP
#define COMPILE_HMG_UNICODE
#include "HMG_UNICODE.h"
#include <windows.h>
HB_FUNC( REGENUMVALUE )
{
DWORD lpType = 1;
TCHAR Buffer[ 255 ];
DWORD dwBuffSize = 255;
DWORD dwClass = 255;
long lError;
lError = RegEnumValueW( ( HKEY ) hb_parnl(1), hb_parnl(2), Buffer, &dwBuffSize, NULL, &lpType, NULL, &dwClass );
if( lError != ERROR_SUCCESS )
hb_retnl( -1 );
else
{
HMG_storc( Buffer, 3 );
hb_stornl( ( long ) dwBuffSize, 4 );
hb_stornl( ( long ) lpType, 6 );
hb_stornl( ( long ) dwClass, 8 );
hb_retnl( lError );
}
}
HB_FUNC( REGCLOSEKEY )
{
HKEY hwHandle = ( HKEY ) hb_parnl( 1 );
if ( RegCloseKey( hwHandle ) == ERROR_SUCCESS )
{
hb_retnl( ERROR_SUCCESS );
}
else
{
hb_retnl( -1 );
}
}
HB_FUNC( REGOPENKEY ) // ( nkey, cSubKey, @nHandle ) --> nResult
{
HKEY hKey = ( HKEY ) hb_parnl( 1 );
HKEY hResult;
hb_retnl( RegOpenKey( hKey, HMG_parc( 2 ), &hResult ) );
hb_stornl( ( LONG ) hResult, 3 );
}
HB_FUNC( REGENUMKEYEXW )
{
FILETIME ft;
long bErr;
TCHAR Buffer[ 255 ];
DWORD dwBuffSize = 255;
TCHAR Class[ 255 ];
DWORD dwClass = 255;
bErr = RegEnumKeyEx( ( HKEY ) hb_parnl( 1 ), hb_parnl( 2 ), Buffer, &dwBuffSize, NULL, Class, &dwClass, &ft );
if( bErr != ERROR_SUCCESS )
hb_retnl( -1 );
else
{
HMG_storc( Buffer, 3 );
hb_stornl( ( long ) dwBuffSize, 4 );
HMG_storc( Class, 6 );
hb_stornl( ( long ) dwClass, 7 );
hb_retnl( 0 );
}
}
HB_FUNC( REGENUMVALUEW )
{
DWORD lpType=1;
TCHAR Buffer[255];
DWORD dwBuffSize = 255;
DWORD dwClass = 255;
long lError;
lError = RegEnumValueW( (HKEY) hb_parnl(1),hb_parnl(2), Buffer, &dwBuffSize, NULL, &lpType, NULL, &dwClass);
if ( lError != ERROR_SUCCESS )
{
hb_retnl(-1);
}
else
{
HMG_storc( Buffer , 3 );
hb_stornl( ( long ) dwBuffSize , 4 );
hb_stornl( ( long ) dwClass , 8 );
hb_retnl( 0 );
}
}
HB_FUNC( REGQUERYVALUEEXW )
{
LONG lError;
DWORD lpType=hb_parnl( 4 );
DWORD lpcbData=0;
lError=RegQueryValueExW( ( HKEY ) hb_parnl( 1 ) , ( LPTSTR ) HMG_parc( 2 ) , NULL , &lpType , NULL , &lpcbData );
if ( lError == ERROR_SUCCESS )
{
BYTE *lpData;
lpData= (BYTE*) malloc( ( int ) lpcbData+1 );
lError= RegQueryValueExW( ( HKEY ) hb_parnl( 1 ) , ( LPTSTR ) HMG_parc( 2 ) , NULL , &lpType , ( BYTE* ) lpData , &lpcbData );
if ( lError > 0 )
{
hb_retnl( -1 );
}
else
{
hb_storc( ( char * ) lpData , 5 );
hb_retnl( 0 );
}
free( ( BYTE* ) lpData );
}
else
hb_retnl( -1 );
}
#pragma ENDDUMP
I think we would add some C function to our libraries... Because IMO, Registry are very important functions.