I have created a small pop-up window which shows all the files in a certain directory. Now I would like to link the files to certain programs based on the extension of the file. To be able to launch the program I need to know were the program has been installed. I do this by looking at the registry for the installation path. I have been succesfull by doing this for excel files. Ext .xls. I have not been able to get the correct path from the registery for Acrobat Reader. The reason is that the registery key is (Default) and it does not want to read it. Does anybody has a clue to correctly read the (Default) key for Adobe installation path. Below a small sample script. Change the path to any directory you would like to read. (Def. c:/public).

#!/perl/bin -w ################################################################### # # Purpose: Declaration of Modules to use in this script ################################################################### use Tk; use strict; use TK::FileSelect; use Tk::LabEntry; use Cwd; use FileHandle; use DirHandle; use Win32::Process; my $W; # GUI window $W = MainWindow->new; $W->title("Select Job"); $W->iconname('select job'); my $file_selected; # Read the directory contents - Put in a path were you have files plac +ed my @dirContents = readDir ("c:/public"); my $job_path = 'c:\\public\\'.$file_selected; print "$job_path\n"; my $TOP = $W->Toplevel; $TOP->title("data contents"); $TOP->geometry("+70+120"); $TOP->configure(-background => lc("aquamarine2")); my $tFrame = $TOP->Frame; my $bFrame = $TOP->Frame; $tFrame->configure(-background => lc("PaleTurquoise")); $bFrame->configure(-background => lc("PaleTurquoise")); # Create the label for editing the file my $lab = $tFrame->Label(-text => "Double click to edit file: ", -background => "PaleTurquoise", -anchor => 'e'); # Create a listbox with the contents of the directory. + my $ent = $tFrame->Scrolled(qw/Listbox -setgrid 1 -height 16 -width 40 + -scrollbars e -selectmode single/); for(@{dirContents}) { $ent->insert(0, "$_"); } $ent->bind('<Double-Button-1>', sub { $file_selected = $ent->get('active'); # In case of Excel files ############### if ($file_selected =~ m/\.xls/) { my $excel; print "$job_path\n"; use Win32API::Registry qw( :ALL ); my ( $key, $type, $excel_path ); #Microsoft Office 95 RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Office\\9.0\ +\excel\\InstallRoot", 0, KEY_READ, $key ); #"$software has registry key\n" : "$software seems to be missing ".r +egLastError()."\n"; if ($key == 0) #Microsoft Office 97 { RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Office\\8. +0\\excel\\InstallRoot", 0, KEY_READ, $key ); } RegQueryValueEx($key, "Path", [], $type, $excel_path, [] ); Win32::Process::Create($excel, $excel_path.'\excel.exe',"excel $job_pa +th",0,CREATE_NEW_CONSOLE,".")|| die ErrorReport(); } elsif ($file_selected =~ m/\.pdf/) { my $pdf; print "$job_path\n"; use Win32API::Registry qw( :ALL ); my ( $key, $type, $pdf_path ); RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Adobe\\Acrobat Reader\\ +5.0\\InstallPath", 0, KEY_READ, $key ); regLastError(); RegQueryValueEx( $key, "(Default)", [], $type, $pdf_path, [] ); print "$pdf_path\n\n\n\n"; Win32::Process::Create($pdf, $pdf_path.'\acrord32.exe',"acrord32 $job_ +path",0,CREATE_NEW_CONSOLE,".")|| die ErrorReport(); } else { my $Notepad; Win32::Process::Create($Notepad,'c:\\program files\\windows NT\\ac +cessories\\wordpad.exe',"wordpad $job_path",0,CREATE_NEW_CONSOLE,".") +|| die ErrorReport(); } }); # Quit the edit directory contents popup my $quitButton = $bFrame->Button(-text => "Quit", -width => 12, -background => "PaleTurquoise", -activebackground => "PaleTurquoise", -command => sub { $TOP->destroy; # strictly not necessary }); # Instead of pack, using grid to place more precisely. Tk::grid($tFrame, -row => 0, -column => 0, -sticky => 'w', -padx => 10, -pady => 10, ); Tk::grid($bFrame, -row => 1, -column => 0, -sticky => 's', -padx => 10, -pady => 10, ); Tk::grid($quitButton, -row => 0, -column => 0, -sticky => 'w', -padx => 10, -pady => 10, ); Tk::grid($lab, -row => 1, -column => 0, -sticky => 'w', -padx => 10, -pady => 10, ); Tk::grid($ent, -row => 1, -column => 1, -sticky => 'w', -padx => 10, -pady => 10, ); MainLoop; sub readDir { my ($DirName) = @_; opendir (INDIR,$DirName) or die "\nCannot open $DirName: $!\n"; my @DirContents = grep (!/^\.\.?$/ && -f "$DirName/$_" , readdir(INDIR +)); close (INDIR); return @DirContents; }

In reply to How to look for application path by juo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.