Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I have my own uninstall program. I want the user to be able to go to the
Start->Control Panel->Add or Remove Programs
and click on it. I then want my program to show amongst all the other currently
installed programs. When the user then clicks on Change/Remove, I want
Windows to automatically invoke my uninstall program.

I am using Perl, but regardless of what language is being used, what are
the steps needed to tell Windows about the uninstall program. It involves
the registry I know, but how, exactly? Or maybe it does not involve the
registry. Maybe it is only a matter of placing the uninstall program in a
certain directory.

I will be incorporating the solution into my install program. Any help would
be appreciated.

Thanks
  • Comment on Getting Windows control panel to invoke an uninstall script

Replies are listed 'Best First'.
Re: Getting Windows control panel to invoke an uninstall script
by ikegami (Patriarch) on Dec 16, 2004 at 21:18 UTC

    It's really just a matter of creating registry key under HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall. The name can be anything; it's not displayed.

    In that key, create the following strings:

    • DisplayName: Set this to what you want displayed in Add/Remove Software.
    • UninstallString: Set this to the uninstall program executable, with appropriate quoting and arguments.
    • DisplayIcon: (optional) Set this to the filename containing the icon.

    For example, the one for IE6 is:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstal +l\IE40] "DisplayName"="Microsoft Internet Explorer 6 SP1" "DisplayIcon"="C:\\Program Files\\Internet Explorer\\iexplore.exe" "UninstallString"="rundll32 C:\\WINNT\\system32\\setupwbv.dll,IE6Maint +enance C:\\Program Files\\Internet Explorer\\IE Uninstall\\W2KEXCP.EX +E /u"

    Someone should be able to recommend you an installer that does this for you.

      Good tip. Thanks. I was able to use Win32::TieRegistry to
      implement it. I ran a couple of "proof of concept" tests. It works okay
      To save others some leg work, here is the code I will be implementing in my installer (Windows ME version):

      use Win32::TieRegistry;
      my $uninstall_path =
      "LMachine\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
      my $uninstall_bat =
      "c:\\Windows\\Profiles\\$loginname\\My\ Documents\\uninstall.bat";

      $key = new Win32::TieRegistry "$uninstall_path";
      $prog_key = $key->CreateKey( "$my_program_name");

      $prog_key->SetValue( "DisplayName", "$my_program_name" );
      $prog_key->SetValue( "UninstallString", "$uninstall_bat" );


      ##########################
      Here is the I will be implementing in my uninstaller (Windows ME version). That is, somewhere in the
      uninstall.bat defined for UninstallString, after all the other uninstall work has been done

      use Win32::TieRegistry;

      my $uninstall_key_path =
      "LMachine\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
      my $key = new Win32::TieRegistry "$uninstall_key_path";
      delete $key->{"\\$my_program_name"};
      undef $key;

        I'd write that more like:

        my $Reg; use Win32::TieRegistry( TiedRef => $Reg, Delimiter => '/' ); $Reg->{ "LMachine/Software/Microsoft/Windows/" . "CurrentVersion/Uninstall/$name/"} = { DisplayName => $name, UninstallString => $uninstallPath, } or die "Can't load registry: $^E";

        But there are a lot of ways to use that module.

        - tye        

      Arrrgh! The uninstall portion of my code had a bug (understatement). Sorry about that.
      The code below has been tested on Windows Millenium.

      use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 );
      my $program_name = "ezbackup";

      $Registry->Delimiter("/"); # $Registry is imported from TieRegistry
      my $uninstall_key =
      $Registry->{"LMachine/Software/Microsoft/Windows/CurrentVersion/Uninstall/"};

      delete $uninstall_key->{"$program_name/DisplayName"};
      delete $uninstall_key->{"$program_name/UninstallString"};
      delete $uninstall_key->{"$program_name/"};

      undef $uninstall_key;