We know that Windows "shortcuts" aren't really symbolic links; only Windows Explorer and certain other applications can make sense of them.
Now your perl program can, too.
This uses OLE to access the contents of a shortcut.
use Win32::OLE; my $wsh = new Win32::OLE 'WScript.Shell'; sub read_shortcut { my $lnk_path = shift; # path of existing .lnk file my $shcut = $wsh->CreateShortcut($lnk_path) or die; $shcut->TargetPath } sub write_shortcut { my $lnk_path = shift; # path of new .lnk file my $target_path = shift; my $comment = shift; # optional my $shcut = $wsh->CreateShortcut($lnk_path) or die; $shcut->{'TargetPath'} = $target_path; $shcut->{'Description'} = $comment if defined $comment; $shcut->Save; } print "c:\\foo.lnk points to ", read_shortcut("c:\\foo.lnk"); # In fact, the shortcut file can be .url too, not just .lnk, # in which case it is an "internet shortcut", and the target # path is a URL. write_shortcut( "c:\\perlmonks.url", "http://perlmonks.org" );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Read and write Windows "shortcut" links (cpan)
by tye (Sage) on Jun 09, 2003 at 15:09 UTC | |
Re: Read and write Windows "shortcut" links
by Anonymous Monk on Feb 22, 2013 at 08:28 UTC | |
by Anonymous Monk on Feb 22, 2013 at 13:40 UTC | |
by jdporter (Paladin) on Feb 22, 2013 at 14:46 UTC |
Back to
Cool Uses for Perl