1 2 //this code will allow you to create a quick and easy registery explorer.3 4 procedure TForm1.FormCreate(Sender: TObject);
5 begin6 //adds the 4 main Registry keys for user to select to explore the registry.7 8 TreeView1.Items.Add(nil,'HKEY_CLASSES_ROOT\');
9 TreeView1.Items.Add(nil,'HKEY_CURRENT_USER\');
10 TreeView1.Items.Add(nil,'HKEY_LOCAL_MACHINE\');
11 TreeView1.Items.Add(nil,'HKEY_CURRENT_CONFIG\');
12 end;
13 14 procedure TForm1.TreeView1Click(Sender: TObject);
15 begin16 //used to get subkeys of a seleced node to display.17 GetSubKeys(TreeView1.Selected);
18 end;
19 20 procedure TForm1.GetSubKeys( tnSub: TTreeNode);
21 var22 slkeys: TStringList; //string list to hold subkeys of main key23 i: Integer; //used to incroment trough string list.24 tnKey: TTreeNode; //tree node to find parent node25 begin26 with TRegistry.Create do27 try28 tnKey:=tnSub;
29 30 while tnKey.Level >0 do// loop to find parent31 tnkey:=tnKey.Parent; //parent node found32 33 //check to find what Key the parent is from and assign it to the34 //registry component to open.35 36 if tnkey.Text ='HKEY_CLASSES_ROOT\' then37 RootKey := HKEY_CLASSES_ROOT
38 elseif tnkey.Text ='HKEY_CURRENT_USER\' then39 RootKey := HKEY_CURRENT_USER
40 elseif tnkey.Text ='HKEY_LOCAL_MACHINE\' then41 RootKey := HKEY_LOCAL_MACHINE
42 elseif tnkey.Text ='HKEY_CURRENT_CONFIG\' then43 RootKey := HKEY_CURRENT_CONFIG;
44 45 if tnSub.Level=0 then// if parent node is selected then get subkeys46 OpenKey( '',false )
47 else48 OpenKey( tnSub.Text,false );//if subnode selected then get subkeys of subnode49 50 slKeys := TStringList.Create;
51 try52 GetKeynames(slkeys); //gets the subkey names of the open parent key.53 CloseKey;
54 TreeView1.Items.EndUpdate;//used to cut down time in display alot of node55 56 for i := 0 to slKeys.Count - 1 do57 begin58 if tnSub.Level=0 thenbegin59 //add subkeys of main keys to tree node.60 TreeView1.items.AddChild(tnSub,slKeys[i]+'\') ;
61 end62 else63 //add subkeys of registry to tree node64 TreeView1.items.AddChild(tnSub,tnSub.Text+ slKeys[i]+'\')
65 end;
66 67 TreeView1.Items.BeginUpdate;//turn on to display nodes68 finally69 slkeys.Free
70 end;
71 finally72 Free;
73 end;
74 end;