Solved

searching registry

Posted on 2001-09-12
4
192 Views
Last Modified: 2011-09-20
i want to search the registry for "winamp" and if its installed, display a message saying "winamp installed" or "winamp not installed"

can someone give me the code to do this?



thanks

ps, sorry to hear about the world trade centre, all my thoughs are with you all!!!

mark
0
Comment
Question by:marksmall
  • 2
  • 2
4 Comments
 
LVL 21

Expert Comment

by:gemarti
ID: 6477350
{Create a new application. Add a listbox and a button.

Add this code. You can modify to compare for WinAmp}

unit unit1;

interface

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

type
 TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;
 Reg : TRegistry;
 Val : TStringList;
 KeyName : String;
implementation

{$R *.DFM}

{var
 ValueName : String;}
{ valueName := ListBox1.Items.Text;
 if KeyName <> '' then
   begin
     Reg.OpenKey(KeyName,False);
     Edit1.Text := Reg.ReadString(ValueName);
   end;}

procedure TForm1.Button1Click(Sender: TObject);
var
 CompName : string;
 i:integer;
begin
 Val.Clear;
 KeyName := '\Software';
 Try
   Reg.RootKey := HKEY_LOCAL_MACHINE;
 Finally
       Reg.OpenKey(KeyName,FALSE);
       Reg.GetKeyNames(Val);
       for i := 0 to Val.Count - 1 do
       ListBox1.Items.Add(Val.Strings[i]);
 end;
end;

Initialization
begin
 Reg := TRegistry.Create;
 Val := TStringList.Create;
end;


Finalization
begin
 Val.Free;
 Reg.CloseKey;
 Reg.Free;
end;
end.
0
 

Author Comment

by:marksmall
ID: 6482141
I have the following code below which finds winamp.exe and if its there is displays its directory, but can someone modify this code so that if it cannot find winamp it displays a message eg  Label1.caption:=('Winamp NOT found');

thanx


private
  procedure ListFiles(D,Name,SearchName : String);

procedure TForm1.ListFiles(D,Name,SearchName : String);
var
    SR            : TSearchRec;
begin
  If D[Length(D)]<>'\' then
    D:=D+'\';
  If FindFirst(D+Name,faAnyFile,SR)=0then
    Repeat
      If (SR.Attr<>faDirectory) and (SR.Name[1]<>'.') then
        If AnsiUpperCase(SR.Name)=AnsiUpperCase(SearchName) then
          Label1.Caption:='Winamp installed on system in: ' + D+SR.Name;{If found then set label1.caption}
    Until (FindNext(SR)<>0);
  FindClose(SR);
  If FindFirst(D+'*.*',faDirectory,SR)=0 then
    begin
      Repeat
        If ((Sr.Attr and faDirectory)=faDirectory) and
            (SR.Name[1]<>'.') then
          ListFiles(D+SR.Name+'\',Name,SearchName);
      Until (FindNext(SR)<>0);
    end;
  FindClose(SR);
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
ListFiles('c:\','*.*','winamp.exe');
0
 
LVL 21

Accepted Solution

by:
gemarti earned 75 total points
ID: 6484169

       If AnsiUpperCase(SR.Name)=AnsiUpperCase(SearchName) then
         Label1.Caption:='Winamp installed on system in: ' + D+SR.Name{If found then set label1.caption}
else
  Lable1.Caption := 'Winamp not installed!';



NOTE: you asked how to search the registry, not the file system.
0
 

Author Comment

by:marksmall
ID: 6628356
SORRY ABOUT DELAY, BEEN POORLY AND COULD GET ACCESS TO MY COMPUTER!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
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…

820 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