Author: Lou Adler
How to jump to a certain key in Regedit?
Answer:
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, Classes, Controls, Forms, StdCtrls;
7
8 type
9 TForm1 = class(TForm)
10 Button1: TButton;
11 procedure Button1Click(Sender: TObject);
12 procedure JumpToKey(Key: string);
13 private
14 { Private declarations }
15 public
16 { Public declarations }
17 end;
18
19 var
20 Form1: TForm1;
21
22 implementation
23
24 {$R *.dfm}
25
26 uses
27 ShellAPI;
28
29 procedure TForm1.JumpToKey(Key: string);
30 var
31 i, n: Integer;
32 hWin: HWND;
33 ExecInfo: ShellExecuteInfoA;
34 begin
35 hWin := FindWindowA(PChar('RegEdit_RegEdit'), nil);
36 if hWin = 0 then
37 {if Regedit doesn't run then we launch it}
38 begin
39 FillChar(ExecInfo, 60, #0);
40 with ExecInfo do
41 begin
42 cbSize := 60;
43 fMask := SEE_MASK_NOCLOSEPROCESS;
44 lpVerb := PChar('open');
45 lpFile := PChar('regedit.exe');
46 nShow := 1;
47 end;
48 ShellExecuteExA(@ExecInfo);
49 WaitForInputIdle(ExecInfo.hProcess, 200);
50 hWin := FindWindowA(PChar('RegEdit_RegEdit'), nil);
51 end;
52 ShowWindow(hWin, SW_SHOWNORMAL);
53 hWin := FindWindowExA(hWin, 0, PChar('SysTreeView32'), nil);
54 SetForegroundWindow(hWin);
55 i := 30;
56 repeat
57 SendMessageA(hWin, WM_KEYDOWN, VK_LEFT, 0);
58 Dec(i);
59 until i = 0;
60 Sleep(500);
61 SendMessageA(hWin, WM_KEYDOWN, VK_RIGHT, 0);
62 Sleep(500);
63 i := 1;
64 n := Length(Key);
65 repeat
66 if Key[i] = '\' then
67 begin
68 SendMessageA(hWin, WM_KEYDOWN, VK_RIGHT, 0);
69 Sleep(500);
70 end
71 else
72 SendMessageA(hWin, WM_CHAR, Integer(Key[i]), 0);
73 i := i + 1;
74 until i = n;
75 end;
76
77 procedure TForm1.Button1Click(Sender: TObject);
78 begin
79 JumpToKey('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer');
80 end;
81
82 end.
|