Skip to content

Commit

Permalink
[+] Win.Registry: CreateKey, TryCreateKey
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdp committed Sep 19, 2021
1 parent f748ffe commit 9459d1c
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions Base/JPL.Win.Registry.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

interface

{$IFDEF MSWINDOWS}
uses
Windows, ShellAPI, Messages, SysUtils, StrUtils, Classes, Registry, Types, JPL.Console,
JPL.Strings, JPL.TStr, JPL.Conversion;
Expand Down Expand Up @@ -49,6 +50,8 @@ TRegistryHelper = class helper for TRegistry
end;

TReg = record
class function CreateKey(const RootKey: HKEY; const Key: string): Boolean; static;
class function TryCreateKey(const RootKey: HKEY; const Key: string): Boolean; static;
class function ExpandRootKey(const Key: string): string; static;
class function IsPredefinedKey(const Key: HKEY): Boolean; static;
class function GetRootKeyFromStr(const Key: string): HKEY; static;
Expand All @@ -64,19 +67,50 @@ TReg = record




{$ENDIF} // MSWINDOWS



implementation



{$IFDEF MSWINDOWS}



{$Region ' TReg '}

class function TReg.CreateKey(const RootKey: HKEY; const Key: string): Boolean;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create(KEY_ALL_ACCESS);
try
Reg.RootKey := RootKey;
Reg.CreateKey(Key);
Result := Reg.KeyExists(Key);
finally
Reg.Free;
end;
end;

class function TReg.TryCreateKey(const RootKey: HKEY; const Key: string): Boolean;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create(KEY_ALL_ACCESS);
try
Reg.RootKey := RootKey;
try
Reg.CreateKey(Key);
except
end;
Result := Reg.KeyExists(Key);
finally
Reg.Free;
end;
end;

class function TReg.ExpandRootKey(const Key: string): string;
var
s: string;
Expand Down Expand Up @@ -266,7 +300,7 @@ class function TReg.RegJump(const Key: string; const ShowCmd: DWORD = SW_SHOWNOR
lpFile := PChar('regedit.exe');
nShow := ShowCmd;
end;
ShellExecuteEx(@sei);
ShellExecuteExW(@sei);
WaitForInputIdle(sei.hProcess, 2000);
hMainWindow := FindWindow(MAIN_WINDOW_CLASS, nil);
end;
Expand Down Expand Up @@ -427,5 +461,7 @@ procedure TRegPath.Clear;
end;


{$ENDIF} // MSWINDOWS


end.

0 comments on commit 9459d1c

Please sign in to comment.