Solved

searching registry

Posted on 2001-09-12
4
189 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now