Listing All Installed Programs in Windows XP

I wanted to get a list of all the programs installed on my computer listed in 'Add or Remove Programs' in the Control Panel in Windows XP. Win32::TieRegistry provided a nice way to do this.

use warnings;
use strict;
use Data::Dumper;

my $Registry;

use Win32::TieRegistry (
  Delimiter   => "/",
  ArrayValues => 1,
  TiedRef     => \$Registry,

my $regkey = 'HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Uninstall/';

my @install_names;
foreach my $software ( values %{$Registry->{$regkey}} ) {
  next unless my $software = $software->{DisplayName};
  next unless $software->[0];
  push @install_names, $software->[0];

print "$_\n" for sort {lc $a cmp lc $b} @install_names;

Win32::TieRegistry installs along with Strawberry Perl.


Probably a little known and even less used module I built, is a parser for the WMIC (Windows Management Instrumentation Command) with is a little known command-line utility that ships all major versions of Windows to allow the getting/setting of all major functions in the OS.

Any information you want is available via this tool, even the "Listing All Installed Programs in Windows XP". What you want can be achieved using the following command.

use Win32::WMIC;

my $wmic = Win32::WMIC->new();
my $data = $wmic->query('product get')->parse;

That looks interesting, but I couldn't get Win32::WMIC to install with Strawberry Perl.

I am using Strawberry Perl 5.10.1. Trying to install Win32::WMIC resulted in failing test

t/query.t ......... 1/? Invalid XSL format (or) file name.

# Failed test 'data variable set'
# at t/query.t line 19.

I tried running your code on ActiveState Perl 5.8.9 on Windows Vista and got the following error message with "use diagnostics":

Can't coerce array into hash at C:\tmp\ line 12 (#1)
(F) You used an array where a hash was expected, but the array has no
information on how to map from keys to array indices. You can do that
only with arrays that have a hash reference at index 0.

The error occurs on statements in the "foreach" loop. One thing that looks strange is the first statement:

next unless my $software = $software->{DisplayName};

because the foreach already defines a "my $software" variable. Any help you can provide regarding this error would be greatly appreciated. Thanks.

Leave a comment

About initself

user-pic Perl is better than sliced bread. Way better.