Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

location of application installed and executable

by juo (Curate)
on Oct 08, 2001 at 11:49 UTC ( #117410=perlquestion: print w/ replies, xml ) Need Help??
juo has asked for the wisdom of the Perl Monks concerning the following question:

Does anybody now in Perl for windows2000 how to find if a certain application is installed and were this is installed. For example : I want to launch excel or wordpad in a Perl script but in order to do that I first need to check if this application is installed and after that I need to know were it is installed so I can launch the executable. Thanks

Comment on location of application installed and executable
Re: location of application installed and executable
by tachyon (Chancellor) on Oct 08, 2001 at 14:56 UTC

    Have a look at Win32API::Registry. The registry holds all kind of deep and dark secrets. Type Start->Run->Regedit to have a browse if you are not familiar with the registry. Don't *change* anything unless you know what you are doing. Here is a short example:

    use Win32API::Registry 0.21 qw( :ALL ); my @software = qw ( Excel Word Outlook PowerPoint Perl ); for my $software (@software) { print RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Offi +ce\\$software", 0, KEY_READ, $key ) ? "$software has registry key\n" : "$software seems to be missing ".regLastError()."\n"; } __END__ Output on my system Excel has registry key Word has registry key Outlook has registry key PowerPoint has registry key Perl seems to be missing The system cannot find the file specified

    Of course Perl is not missing but it is not registered in M$ Office!

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: location of application installed and executable
by jplindstrom (Monsignor) on Oct 08, 2001 at 15:00 UTC
    For me, Excel is in the path and I can imagine that WordPad is always in the path, it being part of the OS.

    So you can start the programs with

    system("excel"); system("wordpad");

    If you want to check for program existance first, try manually iterating over the parts in $ENV{PATH}.

    In the case that Excel for some reason isn't in the path, there is probably some registry key for that... Try searching in your own registry (although that may differ between versions).

    /J

Re: location of application installed and executable
by tachyon (Chancellor) on Oct 08, 2001 at 15:17 UTC

    Here is a more complete example that gets the install root for you as well:

    use Win32API::Registry 0.21 qw( :ALL ); my @software = qw ( Excel Word Outlook PowerPoint Perl ); for my $software (@software) { my ( $key, $type, $data ); print RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Offi +ce\\9.0\\$software\\InstallRoot", 0, KEY_READ, $key ) ? "$software has registry key\n" : "$software seems to be missing ". +regLastError()."\n"; print RegQueryValueEx( $key, "Path", [], $type, $data, [] ) ? "Install Root: $data\n" : "$software ".regLastError()."\n"; } __END__ Excel has registry key Install Root: C:\Program Files\Microsoft Office\Office\ Word has registry key Install Root: C:\Program Files\Microsoft Office\Office\ Outlook has registry key Install Root: C:\Program Files\Microsoft Office\Office\ PowerPoint has registry key Install Root: C:\Program Files\Microsoft Office\Office\ Perl seems to be missing The system cannot find the file specified Perl The configuration registry key is invalid

    Note that 9.0 represents Office 2000

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (16)
As of 2014-07-28 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (201 votes), past polls