We help IT Professionals succeed at work.

How to open regedit and automatically navigate to a key

smartins
smartins asked
on
1,300 Views
Last Modified: 2010-08-05
How can I open regedit.exe and have it automatically navigate to a given key? I can open regedit.exe by simply running it, but I also want it to show a certain key, for example, HKEY_CURRENT_USER\Software.

I know about the LastKey option on the HKEY_USERS\CurrentUserSID\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit but this only works for Windows NT, 2000 and XP.

I've seen some software with this feature on Win9x and ME so there must be something else that can be done.

Thanks,
Steven
Comment
Watch Question

Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Commented:
Neil Rubenking wrote a utility for PCMag in Feb 2001 that was essentially a registry search utility
It had the capability to do what you are asking.

Registry Detective:
http://www.pcmag.com/article2/0,4149,1493427,00.asp

You now have to be a subscriber to download but I downloaded it back when he wrote it. I will
see if I can find it at home.

Contact me at mrbaseball34 at hotmail dot com and I'll send it to you.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2004

Commented:
you could also have your own
registry editor

a not complete sample from my paq

unit reg_entries_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Registry, ImgList, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    TreeView1: TTreeView;
    ImageList1: TImageList;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var
  MyReg : TRegistry;
  MyDataInfo : TRegDataInfo;

procedure CollectRegistry(Path :  String;
                          Reg : TRegistry;
                          ANode : TTreeNode;
                          Nodes : TTreeNodes);
var
  TmpNode : TTreeNode;
  SL : TStringList;
  i : Integer;
  S : String;
begin
  SL := TStringList.Create;   // A stringlist
  try
    Reg.GetValueNames(SL);  // collect valuenames
    for i := 0 to SL.Count - 1 do
    begin
      Reg.GetDataInfo(SL.Strings[I],MyDataInfo);  // get more info
      Case MyDataInfo.RegData of                  //Get Datatypes and values
        rdString,
        rdexpandString : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           S := Path+SL.Strings[I]+' : String = '+Reg.ReadString(SL.Strings[I])
                         else S := Path+SL.Strings[I]+' : String = Not Set';
        rdUnknown      : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           S := Path+SL.Strings[I]+' : Unknown = Not Retrieved yet'
                         else S := Path+SL.Strings[I]+' : Unknown = Not Set';
        rdInteger      : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           S := Path+SL.Strings[I]+' : Integer = '+IntToStr(Reg.ReadInteger(SL.Strings[I]))
                         else S := Path+SL.Strings[I]+' : Integer = Not Set';
        rdBinary       : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           S := Path+SL.Strings[I]+' : Binary = Not Retrieved yet'
                         else S := Path+SL.Strings[I]+' : Binary = Not Set';
        else   //type not in case
          if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
            S := Path+SL.Strings[I]+' : Not Registered Typ = Not Retrieved yet'
          else S := Path+SL.Strings[I]+' : Not Registered Typ = Not Set';
      end;
      TmpNode := Nodes.AddChild(ANode,S);
      TmpNode.ImageIndex := 1;  //show key image
      application.ProcessMessages;  //show the tree grow
    end;
    Reg.GetKeyNames(SL);
    // Start recursion
    for i := 0 to SL.Count - 1 do
    begin
      if Reg.OpenKeyReadOnly('\' + path + SL.Strings[I]) then  //key open for read
      begin
        TmpNode := Nodes.AddChild(ANode,Reg.CurrentPath);
        TmpNode.ImageIndex := 0;  //show folder-image
        CollectRegistry(Reg.CurrentPath +'\', Reg, TmpNode, Nodes);
      end;
    end;
  finally
    sl.free;  // free
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ANode : TTreeNode;
begin
  Button1.Enabled := False;
  MyReg := TRegistry.Create;
  try
    MyReg.RootKey := HKEY_LOCAL_MACHINE;          //set rootkey
    MyReg.OpenKeyReadOnly('\SOFTWARE\Microsoft\');  // open root for read
    TreeView1.Items.Clear;                          // clear tree
    ANode := Treeview1.Items.Add(Nil,MyReg.CurrentPath);
    ANode.ImageIndex := 0;
    CollectRegistry(MyReg.CurrentPath,MyReg,ANode,TreeView1.Items);  //start Search
  finally
    MyReg.Free;
  end;
  Button1.Enabled := True;
end;

end.

meikl ;-)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.