Monday, November 12, 2007

Automated Deployment, Part I: Uninstall The Olde Crap

To harvest the command line to uninstall an application, launch the regedit application and browse the registry tree to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, each key afterwards is a application key, a string of characters that means nothing if it is coded by baboon(s). The crucial items are these value name of the application key and it's content:
  1. DisplayName: the name of the application
  2. UninstallString: the command line to uninstall the application.
To get all of the useful information using perl:

use strict;
use Win32::TieRegistry;
my $machine = 'localhost'; # make sure the RemoteRegistry services is up
# and the script is executed with user within
# administrator group.
my $register = 'HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows'.
'/CurrentVersion/Uninstall';
$register = "//$machine/$register";

$Registry->Delimiter("/");
my $remoteKey = $Registry->{$Register};
if (defined $remoteKey) {
foreach my $appKey ( $remoteKey->SubKeyNames ) {
my $DisplayName = $Registry->{"$Register/$appKey/DisplayName"};
my $UninstallString = $Registry->{"$Register/$appKey/UninstallString"};
if (defined $UninstallString && defined $DisplayName) {
$app{$DisplayName} = $UninstallString;
}
}
}
open LOG, ">$0.txt";
foreach my $appName (sort keys %app) {
print LOG "$appName, $app{$appName}\n";
}
close LOG;

Usually, there are two kinds of command line, the first one is an executable binary and customized MSI script (the command line starts with msiexec.exe). If you happen to encounter the later one, you are in luck, if not, pray that the baboon put in the quiet mode in the binary.

If the uninstallation string uses msiexec.exe, just put in /quiet at the back of the string to launch quiet installation.

No comments: