ajregistry.pas

来自「是不是天天看見MS的注冊表看膩了」· PAS 代码 · 共 73 行

PAS
73
字号


unit ajRegistry;



interface

uses
  Windows;

{..................................................................................................}

const
  cNumRegHKEYKeys = 5; // Number of keys supported.
  cRegHKEYLookUp  : array[1..cNumRegHKEYKeys] of record
    Description : string;
    Value       : HKEY;
  end = ((Description : 'HKEY_CLASSES_ROOT'; Value : HKEY_CLASSES_ROOT),
         (Description : 'HKEY_CURRENT_USER'; Value : HKEY_CURRENT_USER),
         (Description : 'HKEY_LOCAL_MACHINE'; Value : HKEY_LOCAL_MACHINE),
         (Description : 'HKEY_USERS';  Value : HKEY_USERS),
         (Description : 'HKEY_CURRENT_CONFIG'; Value : HKEY_CURRENT_CONFIG));

{..................................................................................................}

function RegNumSubKeys  (HKEYValue : HKEY; SubKey : string) : integer;
function HKEYTextToHKEY (HKEYText : string) : HKEY;

implementation

uses
  SysUtils;

{--------------------------------------------------------------------------------------------------}
{                                       Registry Functions                                         }
{--------------------------------------------------------------------------------------------------}

function HKEYTextToHKEY(HKEYText : string) : HKEY;
var
  lp1 : integer;
begin
  lp1 := 0;
  repeat
    inc(lp1);
  until (cRegHKEYLookUp[lp1].Description = HKEYText) or (lp1 = cNumRegHKEYKeys);

  if (cRegHKEYLookUp[lp1].Description = HKEYText) then
    Result  := cRegHKEYLookUp[lp1].Value
  else
    raise Exception.Create(HKEYText + ' - Invalid HKEY description');
end; {HKEYTextToHKEY}

{--------------------------------------------------------------------------------------------------}

function RegNumSubKeys(HKEYValue : HKEY; SubKey : string) : integer;
// Returns the number of keys.
var
  Key         : HKEY;
  NumSubKeys  : DWORD;
begin
  Result  := 0;
  if (RegOpenKeyEx(HKEYValue, PChar(SubKey), 0, KEY_QUERY_VALUE, Key) = ERROR_SUCCESS) then begin
    if (RegQueryInfoKey(Key, nil, nil, nil, @NumSubKeys, nil, nil, nil, nil, nil, nil, nil) = ERROR_SUCCESS) then
      Result  := NumSubKeys;
    RegCloseKey(Key);
  end; {if}
end; {RegNumSubKeys}

{--------------------------------------------------------------------------------------------------}
{ajRegistry}
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?