Board index » delphi » Accessing HKEY_LOCAL_MACHINE key in Win95 Registry

Accessing HKEY_LOCAL_MACHINE key in Win95 Registry

Hi There,

I'm trying to write a routine that reads the current username and
hostname from HKEY_LOCAL_MACHINE hive key in the registry.

However, using the ShellAPI functions I can only access the
HKEY_CLASSES_ROOT key. In fact, that is the only key defined in the
'shellapi.pas' source file.

Whenever I try to open any other hive key with 'RegOpenKey' i get
ERROR_BADKEY returned.

Any ideas ?  Thanks in Advance, Neil Pearson

 

Re:Accessing HKEY_LOCAL_MACHINE key in Win95 Registry


Quote
>   Neil Pearson <ne...@pncl.co.uk> writes:
>  Hi There,

>  I'm trying to write a routine that reads the current username and
>  hostname from HKEY_LOCAL_MACHINE hive key in the registry.

>  However, using the ShellAPI functions I can only access the
>  HKEY_CLASSES_ROOT key. In fact, that is the only key defined in the
>  'shellapi.pas' source file.

>  Whenever I try to open any other hive key with 'RegOpenKey' i get
>  ERROR_BADKEY returned.

>  Any ideas ?  Thanks in Advance, Neil Pearson

I assume that you are using Delphi 1.  In order to access the extra features of '95, including
the HKEY_USERS and HKEY_LOCAL_MACHINE hives, you will need to use Delphi 2.

Also, in Delphi 1, you can only change or query a registry value of REG_SZ type.  I believe
that this problem is addressed in Delphi 2.

It is my understanding that this is a limitation of the 16-bit API, and not Delphi.

Re:Accessing HKEY_LOCAL_MACHINE key in Win95 Registry


Quote
RandyN...@Linknet.Net wrote:
>>   Neil Pearson <ne...@pncl.co.uk> writes:
>>  Hi There,

>>  I'm trying to write a routine that reads the current username and
>>  hostname from HKEY_LOCAL_MACHINE hive key in the registry.

>>  However, using the ShellAPI functions I can only access the
>>  HKEY_CLASSES_ROOT key. In fact, that is the only key defined in the
>>  'shellapi.pas' source file.

>>  Whenever I try to open any other hive key with 'RegOpenKey' i get
>>  ERROR_BADKEY returned.

>>  Any ideas ?  Thanks in Advance, Neil Pearson

>I assume that you are using Delphi 1.  In order to access the extra features of '95, including
>the HKEY_USERS and HKEY_LOCAL_MACHINE hives, you will need to use Delphi 2.

Somewhat untrue......

I use these all the time for Win95 registry access:

const
{ These were lifted from the WINREG.H file from BC++ 4.52 }
   HKEY_CLASSES_ROOT  = $80000000;
   HKEY_CURRENT_USER  = $80000001;
   HKEY_LOCAL_MACHINE = $80000002;
   HKEY_USERS         = $80000003;

and use them something like this:

const
  RegSecRoot : pChar = 'Software\t.h.ink\SecServer';

var
    FAppKey : hKey;
    FAppName : string;
    FRootKey : hKey;

< some code here >

  FRootKey := 0;
  FAppName := '';
  FActive := FALSE;
  RegSecRoot : pChar = 'Software\t.h.ink\SecServer';
  if RegCreateKey(HKEY_CURRENT_USER,RegSecRoot,FRootKey) <> ERROR_SUCCESS then
  begin
    raise ESecurityBadDB.Create('Unable to access Security Registry Root!');
  end;

and so on...

- Show quoted text -

Quote
>Also, in Delphi 1, you can only change or query a registry value of REG_SZ type.  I believe
>that this problem is addressed in Delphi 2.
>It is my understanding that this is a limitation of the 16-bit API, and not Delphi.

Other Threads