CUFP
jdporter
snippet
<div class="Description">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.</div>
<CODE>
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" );
</CODE>