Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
No such thing as a small change
 
PerlMonks  

How to obtain a list of software applications installed on a Win based PC?

by Anonymous Monk
on Jun 01, 2004 at 12:36 UTC ( #358008=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi

Using Perl, how can I obtain a list of software applications that are installed on a windows XP based PC?

Is there a library that I can use to achieve this?

Many Thanks for your help in advance

Highest Regards

Comment on How to obtain a list of software applications installed on a Win based PC?
Re: How to obtain a list of software applications installed on a Win based PC?
by davidj (Priest) on Jun 01, 2004 at 13:27 UTC
    Windows application configuration information is stored in the Registry (if, I believe, it has been properly installed according to Microsoft installation conventions). I am no Windows, guru, but I do believe that this information mostly resides in:
    HKEY_LOCAL_MACHINE->SOFTWARE
    HKEY_CURRENT_USER->SOFTWARE

    You might try taking a look at Win32API::Registry and Tie::Registry
    Both of these modules are designed for manipulating/querying the Windows Registry.

    hope this helps,
    davidj
      Yes thanks, it does help.

      Blackadder
Re: How to obtain a list of software applications installed on a Win based PC?
by BrowserUk (Pope) on Jun 01, 2004 at 13:45 UTC

    It very much depends upon what you class as an "installed application"?

    If your definition would be based upon that list of applications that you could uninstall using the Control_Panal->Add/remove Programs panel, then you can obtain that list from the registry under the key HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

    Then simply enumerate all the entries and fetch the "DisplayName" value from each one.

    Beyond that, anything installed that doesn't register itself with the MS mechanisms is not easily quantified or detected.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
      Thanks for you help and information.

      I will try the registery approach.

      Regards

      BlackAdder
      Hi

      I tried this bit of code, however I did not get any information about the installed applications (only 'Done' was displyed).

      Can some one shed light on this for me please.

      use strict; use Win32::Registry; my $Key; if ($HKEY_LOCAL_MACHINE->Open("Software\\Microsoft\\Windows\\CurrentVe +rsion\\Uninstall", $Key)) { print "\nDone1\n"; my %ValueList; $Key->GetValues(\ %ValueList); # nothing happens here! for my $item (keys(%ValueList)) # nor here { print "\nDone2 $item\n"; print "$item : $ValueList{$item}[2]\n"; } print $Key->{DisplayName}."\n"; $Key->Close(); }
      Thanks for the help indeed.

        You need to distinguish between what are termed "Keys" and what "Values". This may get you started.

        #! perl -slw use strict; use Win32::Registry; use Data::Dumper; my $key; $HKEY_LOCAL_MACHINE->Open( "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", $key ) or die $^E; my @keys; $key->GetKeys( \@keys ); for my $subkey ( @keys ) { $key->Open( $subkey, my $x ) or die $^E; my %vals; $x->GetValues( \%vals ); print Dumper \%vals; }

        You may also want to consider Win32::TieRegistry.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
Re: How to obtain a list of software applications installed on a Win based PC?
by wufnik (Friar) on Jun 01, 2004 at 13:57 UTC
    in line with davidj's suggestion, here is some code which will give you a list of the software in HKEY_LOCAL_MACHINE/SOFTWARE.

    add other relevant registry keys to taste.
    my %RegHash; use Win32::TieRegistry( TiedHash => \%RegHash, Delimiter => "/"); my $registry = \%RegHash; @regkeys = keys %{$registry->{'HKEY_LOCAL_MACHINE/SOFTWARE/'}}; print join "\n", @regkeys;
    all the best...
    ...wufnik

    -- in the world of the mules there are no rules --
      THANKS FOR THIS,...I think it worked! although it dumped out stuff that i don't think that they are installed applications!

      here is the output
      ActiveState/ Adobe/ Apple Computer, Inc./ ArcSoft/ C07ft5Y/ Classes/ Clients/ DataDirect/ Documentum/ Gemplus/ IDM Computer Solutions, Inc./ InstalledOptions/ InstallShield/ Intel/ JavaSoft/ L&H/ Licenses/ Microsoft/ Netscape/ Nikon/ NVIDIA Corporation/ ODBC/ Perl/ pixology/ PlaceWare/ Policies/ Program Groups/ Reflectent/ Schlumberger/ Secure/ SYBASE/ Symantec/ VisionShape/ VMware, Inc./ Wilson WindowWare/ Windows 3.1 Migration Status/ Description/
      This output is very ambigouis! I have Office2003 installed and What I excpected is to see WinWord, Excel, OutLook, Access all to be listed. Also I have never seen -or heard -of some of the listed software in the above output!! So I don't understand what went on there!

      Is it possible to use this code below to obtain the information - once it get de-bugged and since I can understand it a bit better than the one using the Registry tie?
      use strict; use Win32::Registry; my $Key; if ($HKEY_LOCAL_MACHINE->Open("Software\\Microsoft\\Windows\\CurrentVe +rsion\\Uninstall", $Key)) { print "\nDone1\n"; my %ValueList; $Key->GetValues(\ %ValueList); # nothing happens here! for my $item (keys(%ValueList)) # nor here { print "\nDone2 $item\n"; print "$item : $ValueList{$item}[2]\n"; } print $Key->{DisplayName}."\n"; $Key->Close(); }
      Thanks & Your Help is highly appreciated.

        Here's what you are looking for.

        #!perl use warnings; use strict; use Data::Dumper; my $Registry; use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1, TiedRef => \$Registry, ); my @install_names; foreach my $software ( values %{$Registry->{'HKEY_LOCAL_MACHINE/Softwa +re/Microsoft/Windows/CurrentVersion/Uninstall/'}} ) { 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;
Re: How to obtain a list of software applications installed on a Win based PC?
by gsiems (Chaplain) on Jun 01, 2004 at 16:58 UTC
    You might also like to check out this node.
      Hi Anonymous Monk,

      when i save you code in "test1.pl", i'll get:
      D:\perl>perl neu.pl
      Can't use an undefined value as a HASH reference at test1.pl line 15.

      I read about registry reflection and "Wow6432Node", but i'm not able to change your code to get it running on my 64Bit Windows machine. Can someone give me hint's?
      Yours nubbel

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://358008]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-04-20 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls