0

以下に説明するように、Windows レジストリにいくつかのノードとサブノードを作成するための Delphi XE2 プロジェクトを 1 つ持っています。
アプリケーション ウィザード

次のコードを定義しました。

function GetWinDir: string;
var
  WindowsDirectory: array[0..MAX_PATH] of Char;
begin
   GetWindowsDirectory(WindowsDirectory, MAX_PATH - 1);
   SetLength(Result, StrLen(WindowsDirectory));
   Result := IncludeTrailingPathDelimiter(WindowsDirectory);
end;

function GetSysDir: string;
var
  SystemDirectory: array[0..MAX_PATH] of Char;
begin
  GetSystemDirectory(SystemDirectory, MAX_PATH - 1);
  SetLength(Result, StrLen(SystemDirectory));
  Result := IncludeTrailingPathDelimiter(SystemDirectory);
end;

function GetSysNativeDir: string;
var
  WindowsDirectory: array[0..MAX_PATH] of Char;
begin
   GetWindowsDirectory(WindowsDirectory, MAX_PATH - 1);
   SetLength(Result, StrLen(WindowsDirectory));
   Result := IncludeTrailingPathDelimiter(WindowsDirectory)  + 'Sysnative\';
end;

procedure TMainForm.BitBtn01Click(Sender: TObject);
var
  RegistryEntry : TRegistry;
  RegistryEntryValue : string;   
begin
  RegistryEntry := TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);
  RegistryEntry.RootKey := HKEY_CLASSES_ROOT;
  if (not RegistryEntry.KeyExists('CLSID\{BE800AEB-A440-4B63-94CD-AA6B43647DF9}\')) then
    begin
      RegistryEntry.Access:= KEY_WRITE or KEY_WOW64_64KEY;
      if RegistryEntry.OpenKey('CLSID\{00000000-0000-0000-0000-000000000001}\',true) then
        begin
          Memo01.Font.Color := 3992580;
          Memo01.Lines.Add('Windows Registry Entry Has Been Found In Your System');
          RegistryEntry.WriteString('', 'Delphi Application Wizard');
          RegistryEntry.OpenKey('Subnode 01\',true);
          RegistryEntry.WriteExpandString('', '%SystemRoot%\System32\Application Wizard 01.dll');
          RegistryEntry.WriteString('Subnode String 01', '00001');
          RegistryEntry.CloseKey();
          RegistryEntry.OpenKey('CLSID\{00000000-0000-0000-0000-000000000001}\Subnode 02\',true);
          RegistryEntry.WriteExpandString('', '%SystemRoot%\System32\Application Wizard 02.dll');
          RegistryEntry.WriteString('Subnode String 02', '00002');
          RegistryEntry.CloseKey();
          RegistryEntry.OpenKey('CLSID\{00000000-0000-0000-0000-000000000001}\Subnode 03\',true);
          RegistryEntry.WriteExpandString('', '%SystemRoot%\System32\Application Wizard 03.dll');
          RegistryEntry.WriteString('Subnode String 03', '00003');
          RegistryEntry.CloseKey();
          RegistryEntry.OpenKey('CLSID\{00000000-0000-0000-0000-000000000001}\Subnode 04\',true);
          RegistryEntry.WriteExpandString('', '%SystemRoot%\System32\Application Wizard 04.dll');
          RegistryEntry.WriteString('Subnode String 04', '00004');
          RegistryEntry.CloseKey();
          RegistryEntry.OpenKey('CLSID\{00000000-0000-0000-0000-000000000001}\Subnode 05\',true);
          RegistryEntry.WriteExpandString('', '%SystemRoot%\System32\Application Wizard 05.dll');
          RegistryEntry.WriteString('Subnode String 05', '00005');
          Memo01.Font.Color := 3992580;
          Memo01.Lines.Add('Windows Registry Entry Has Been Created Successfully')
        end
      else if RegistryEntry.OpenKey('CLSID\{00000000-0000-0000-0000-000000000001}\',false) then
        begin
          Memo01.Font.Color := 7864575;
          Memo01.Lines.Add('Windows Registry Entry Has Not Been Created Successfully')
        end
    end
  else
    begin
      if (RegistryEntry.KeyExists('CLSID\{00000000-0000-0000-0000-000000000001}\')) then
        begin
          Memo01.Font.Color := 7864575;
          Memo01.Lines.Add('Windows Registry Entry Has Been Found In Your System')
        end;
    end;
  RegistryEntry.CloseKey();
  RegistryEntry.Free;
end;

..
..
..
..
..
procedure TMainForm.BitBtn02Click(Sender: TObject);
var
  RegistryEntry : TRegistry;
begin
  RegistryEntry := TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);
  RegistryEntry.RootKey := HKEY_CLASSES_ROOT;
  if (RegistryEntry.KeyExists('CLSID\{00000000-0000-0000-0000-000000000001}\')) then
    begin
      Memo01.Font.Color := 3992580;
      Memo01.Lines.Add('Windows Registry Entry Has Been Found In Your System');
      RegistryEntry.Access:= KEY_WRITE or KEY_WOW64_64KEY;
      RegistryEntry.DeleteKey('CLSID\{00000000-0000-0000-0000-000000000001}\Subnode 01\');
      RegistryEntry.DeleteKey('CLSID\{00000000-0000-0000-0000-000000000001}\Subnode 02\');
      RegistryEntry.DeleteKey('CLSID\{00000000-0000-0000-0000-000000000001}\Subnode 03\');
      RegistryEntry.DeleteKey('CLSID\{00000000-0000-0000-0000-000000000001}\Subnode 04\');
      RegistryEntry.DeleteKey('CLSID\{00000000-0000-0000-0000-000000000001}\Subnode 05\');
      RegistryEntry.DeleteKey('CLSID\{00000000-0000-0000-0000-000000000001}\');
      RegistryEntry.CloseKey();
      RegistryEntry.Free;
      Memo01.Font.Color := 16756480;
      Memo01.Lines.Add('Windows Registry Entry Has Been Deleted Successfully');
    end
  else
    begin
      Memo01.Font.Color := 7864575;
      Memo01.Lines.Add('Windows Registry Entry Has Not Been Found In Your System');
    end;
end;  

私の質問は次のとおりです。

  1. すべてのサブノードのデフォルト文字列を書き込もうとしていますが、%SystemRoot%\System32\Application Wizard 01.dllまだ%SystemRoot%\SysWow64\Application Wizard 01.dll書かれています。それを避ける方法は?

  2. CloseKey();サブノード 01 に文字列を書き込んだ後、サブノード 02 に文字列を書き込もうとすると、コードで行ったように、毎回OpenKeyメイン ノードを呼び出す必要があるかどうかにかかわらず、. または、他の解決策はありますか?

  3. いくつかのコードを使用してメイン ノードを削除する場合は、最初にサブノード 05 を削除し、次にサブノード 04 を削除する必要があります。すべてのサブノードを削除した後でのみ、メイン ノードを削除できます。サブノードに別のサブノードが含まれている場合は、それらを確認します。これらのサブノードを削除する代わりに、メイン ノードを直接削除する解決策はありますか?

4

1 に答える 1