Einzelnen Beitrag anzeigen

Chrischi

Registriert seit: 8. Aug 2008
21 Beiträge
 
#27

Re: Programmpfad anderer Programme ermitteln

  Alt 8. Aug 2008, 21:45
Delphi-Quellcode:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
const
  UNINST_PATH = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall';
var
  Reg: TRegistry;
  SubKeys: TStringList;
  ListItem: TlistItem;
  i: integer;
  sDisplayName, sUninstallString: string;
begin
{
  ListView1.ViewStyle := vsReport;
  ListView1.Columns.add;
  ListView1.Columns.add;
  ListView1.Columns[0].caption := 'DisplayName';
  ListView1.Columns[1].caption := 'UninstallString';
  ListView1.Columns[0].Width := 300;
  ListView1.Columns[1].Width := 300;
}

  Reg := TRegistry.Create;

    try
        try
           Listview1.Items.BeginUpdate;
           Listview1.Items.Clear;
           Reg.RootKey := HKEY_LOCAL_MACHINE;
          if Reg.OpenKeyReadOnly(UNINST_PATH) then
          begin
            SubKeys := TStringList.Create;
            try
              Reg.GetKeyNames(SubKeys);
              Reg.CloseKey;
              for i := 0 to subKeys.Count - 1 do
                if Reg.OpenKeyReadOnly(Format('%s\%s', [UNINST_PATH, SubKeys[i]])) then
                  try
                    sDisplayName := Reg.ReadString('DisplayName');
                    sUninstallString := Reg.ReadString('UninstallString');
                    if sDisplayName <> 'then
                    begin
                      ListItem := Listview1.Add;
                      ListItem.Caption := sDisplayName;
                      ListItem.subitems.Add(sUninstallString);
                    end;
                  finally
                    Reg.CloseKey;
                  end;
            finally
              SubKeys.Free;
            end;
          end;
        finally
          ListView1.AlphaSort;
          Listview1.Items.EndUpdate;
        end;
    finally
      Reg.CloseKey;
      Reg.Free;
    end;
end;

end.
  Mit Zitat antworten Zitat