Solved

How do i search the Windows Regestery?

Posted on 1997-05-23
1
178 Views
Last Modified: 2010-04-04
From Delphi that is.

There is a TRegestry type component in Delphi that permits me to read and write to the regestry, but it does not seem to have a search facility.

All installed programs have there .EXE in the regestry, eg Word for windows, so when i want to run word from my application, it would be wisest to get the path from the regestry, (as it could of been moved from its default path).  to find its path i could do with a TRegestry.search(....) type function.  ayone know know what to write?

I would imagine it would look somthing like For 1 to Tregestry.GetKeyNames[list of key names for the regerstry root] do
move through each one using Copy(Tregestry.keyname.ReadString), last 8 letters) = Word.EXE
.......................
Or if i knew that it was always in a particulr Root, (eg
00020901-0000-0000-c000-0000000046) but who on earth knows such things.

.................
Or perhaps if anyone knows the OLE/DDE type code to access the Windows Regestry editor and POKE or whatever a Find at it?

..................
Or perhaps some API that will search files, (i do not know much about how to get at or uses Win API calls, but somthing like a FileSearchTree(filehandel, .exename) type call?
.................
Or am i just barking up the wrong tree all together.
........................

Anyone know the best way to search for the current directory of the .EXE
Martin.  
0
Comment
Question by:MARTIN030397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
erajoj earned 50 total points
ID: 1336546
As usual, my answer is basic, but it seems to work well.
Just create a TRegistry object and call:
  SeekRegistry(Reg, '\software', 'delphi', rsKey);
    or
  SeekRegistry(Reg, '', 'c:\netscape', rsStr);
    or
  SeekRegistry(Reg, '', '1997', rsInt);
    or
  Something like that...

It uses a recursive procedure that scans all subkeys(strings/integers) from a start key (you'll figure it out).
If you can't make it work the way you want; let me know!

Here goes:

type
  RegSearchModes = (rsKey, rsStr, rsInt);

procedure SeekRegistry(var Reg: TRegistry; KeyPath, Criteria: string; Mode: RegSearchModes);
{ This can be a stack hog! }
var
  Keys, Vals : TStringList;
  Index      : Integer;
begin
  Reg.OpenKey(KeyPath, False);
  if Mode in [rsStr, rsInt] then begin
    Vals := TStringList.Create;
    Reg.GetValueNames(Vals);
    for Index := 0 to Vals.Count-1 do
    case Mode of
      rsStr: if Reg.GetDataType(KeyPath+'\'+Vals[Index]) = rdString then begin
        if Pos(UpperCase(Criteria), UpperCase(Reg.ReadString(KeyPath+'\'+Vals[Index])))>0
        then { Do something with the found string! };
      end;
      rsInt: if Reg.GetDataType(KeyPath+'\'+Vals[Index]) = rdInteger then begin
        if StrToInt(Criteria)=Reg.ReadInteger(KeyPath+'\'+Vals[Index])
        then { Do something with the found integer! };
      end;
    end;
    Vals.Free;
  end;
  Keys := TStringList.Create;
  Reg.GetKeyNames(Keys);
  for Index := 0 to Keys.Count-1 do begin
    if (Mode=rsKey) then if Pos(UpperCase(Criteria), (Keys[Index]))>0
    then { Do something with the found key! };
    SeekRegistry(Reg, KeyPath+'\'+Keys[Index], Criteria, Mode);
  end;
  Keys.Free;
end;

procedure TMainForm.Button9Click(Sender: TObject);
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CURRENT_USER;
  SeekRegistry(Reg, '', Edit4.Text, rsKey);
  Reg.Free;
end;

Simple, huh?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question