#!/usr/bin/perl
use strict;
use warnings;
use Win32::TieRegistry;

my $nom_logiciel = 'ActivePerl';
if ( my $RefInfoPerl = GetProductCode($nom_logiciel) ) {
  foreach my $cle ( keys %{$RefInfoPerl} ) {
    print "$cle : $RefInfoPerl->{$cle}\n";
  }
}

sub GetProductCode {
  my $Name         = shift;
  my $RegistryPath = 'HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall';
  my %InfoProduct;

  $Registry->Delimiter('/');
  my $SubKey = $Registry->{$RegistryPath} or die "Lecture impossible : $RegistryPath\n$^E\n";

  foreach my $key ( keys %{$SubKey} ) {
    my $RefName = $SubKey->{$key}{DisplayName};

    if ( $RefName and $RefName =~ m{$Name}i ) {
      $InfoProduct{Code} = $key;
      if ( exists $SubKey->{$key}{DisplayName} ) {
        $InfoProduct{DisplayName} = $SubKey->{$key}{DisplayName};
      }
      if ( exists $SubKey->{$key}{InstallLocation} ) {
        $InfoProduct{InstallLocation} = $SubKey->{$key}{InstallLocation};
      }
      if ( exists $SubKey->{$key}{DisplayVersion} ) {
        $InfoProduct{DisplayVersion} = $SubKey->{$key}{DisplayVersion};
      }
      if ( exists $SubKey->{$key}{InstallDate} ) {
        $InfoProduct{InstallDate} = $SubKey->{$key}{InstallDate};
      }
      last;
    }
  }

  return \%InfoProduct;
}