Thursday, September 10, 2009

Add or Remove Programs is too freaking slow?

I really hate Windows Add or Remove Programs it takes so much time that I freak out.
Why it takes so much time? I believe it gathers information about every program, like: when was the last time started, how many times, who used the program, bla bla bla.
Anyways here's a screenshot of my dUninstaller in action

The implementation is very simple, reads some registry keys and shows you the information almost like "Add or Remove Programs" does.
So all you need is a constant
  UNINSTALLROOT = '\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\';

and then a way to display the info in a TListView from the Win32 palette
procedure TfrmMain.btnRefreshClick(Sender: TObject);
  theRegistry: TRegistry;
  uEntries: TStrings;
  index: Integer;
  item: TListItem;
  uEntries := TStringList.Create;
  theRegistry := TRegistry.Create;
  theRegistry.RootKey := HKEY_LOCAL_MACHINE;
  theRegistry.OpenKey(UNINSTALLROOT, False);

  for index := 0 to uEntries.Count -1 do begin
    theRegistry.OpenKey(UNINSTALLROOT + uEntries[index], False);
    if theRegistry.ValueExists('DisplayName') then begin
      item := uList.items.add;
      item.Caption := theRegistry.ReadString('DisplayName');
      if theRegistry.ValueExists('DisplayVersion') then
        item.SubItems.Add(theRegistry.ReadString('DisplayVersion')) else
      if theRegistry.ValueExists('Publisher') then
        item.SubItems.Add(theRegistry.ReadString('Publisher')) else
      if theRegistry.ValueExists('UninstallString') then
        item.SubItems.Add(theRegistry.ReadString('UninstallString')) else
        if theRegistry.ValueExists('QuietUninstallString') then
          item.SubItems.Add(theRegistry.ReadString('QuietUninstallString')) else

  StatusBar.SimpleText := Format('%d Application(s)', [uList.Items.Count]);

now to uninstall a program you must select it form the list and when you press the Uninstall button it triggers this event
procedure TfrmMain.btnUninstallClick(Sender: TObject);
  sUninstall: String;
  if uList.ItemIndex = -1 then
  sUninstall := uList.ItemFocused.SubItems[2];
  if sUninstall <> 'null' then begin
    WinExec(PChar(sUninstall), SW_SHOWDEFAULT);

And that's about it, you download the application or the source code if you wish.

No comments:

Post a Comment

Blogroll(General programming and Delphi feeds)