Solved

How do i search the Windows Regestery?

Posted on 1997-05-23
1
175 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 80
Error E2158 compiling with Delphi XE10 Seattle 2 142
migrate this code to work on android 1 46
Get weeknumber and year from date 4 57
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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