// Registry an einem bestimmten Key öffnen.


// Getestet mit D4 unter XP

uses ShellAPI, CommCtrl; 
 
procedure KeySelect(Key: string); 
const 
  waiting = 320; 
  clss = 'RegEdit_RegEdit'; 
var 
  x: Integer; 
  H, HS: THandle; 
begin 
  H := FindWindow(clss, nil); 
  if H <> 0 then begin 
    sendmessage(H, WM_CLOSE, 0, 0); 
    sleep(waiting); 
  end; 
  shellexecute(0, 'open', 'regedit.exe', nil, nil, SW_HIDE); 
  sleep(waiting); 
  H := FindWindow(clss, nil); 
  HS := FindWindowEx(H, 0, 'SysTreeView32', nil); 
  SetForegroundWindow(HS); 
  TreeView_Expand(HS, TreeView_GetRoot(HS), TVE_COLLAPSE); 
  SendMessage(HS, WM_KEYDOWN, VK_RIGHT, 0); 
  sleep(waiting); 
  if (Key <> '') and (Ansilastchar(Key) = '\') then 
    Key := copy(Key, 1, pred(length(Key))); 
  for x := 1 to length(Key) do begin 
    if Key[x] = '\' then begin 
      SendMessage(HS, WM_KEYDOWN, VK_RIGHT, 0); 
      sleep(waiting); 
    end else 
      SendMessage(HS, WM_CHAR, Integer(Key[x]), 0); 
  end; 
  ShowWindow(H, SW_SHOWNORMAL); 
  SetForegroundWindow(H); 
end; 
 
 
// Beispielaufruf 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
  Label1.visible := false; 
  Label1.Font.name := 'Arial'; 
  Label1.Font.Size := 18; 
  Label1.Font.Style := [fsBold]; 
  Label1.caption := 'Moment bitte!'; 
end; 
 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  screen.cursor := crHourGlass; 
  Label1.visible := true; 
  application.processmessages; 
  KeySelect('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'); 
  Label1.visible := false; 
  screen.cursor := crDefault; 
end;



 

Zugriffe seit 6.9.2001 auf Delphi-Ecke