cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
Following suggestions in node Read and write Windows "shortcut" links I have tried doing it with Image::ExifTool and Win32::OLE (had trouble installing the other two mods suggested):
use strict; use feature ':5.10'; use Data::Dumper; use Image::ExifTool qw(:Public); use Win32::OLE; # cwd is c:/tmp/ say "exiftool\n"; my $info = ImageInfo("c:/tmp/test/link.lnk"); say Dumper($info); say "\nOLE\n"; my $wsh = new Win32::OLE 'WScript.Shell'; my $shcut = $wsh->CreateShortcut("c:/tmp/test/link.lnk") or die; say $shcut->TargetPath
This is pointing to a shortcut in a subfolder test where I inserted "https://perlmonks.org" in the box labeled "Type the location of this item:" and "link" in "Type a name for this shortcut:"
The first approach yields "error opening file" and the second one dies. I was a little skeptical of the code for the second because the method is "CreateShortcut" whereas I am trying to read one.
I tried changing the name of the link to link.lnk and tried again. No difference for the first approach. The second one didn't die, but returned null.
So then I think to myself: "Self, maybe these are just designed for links to other folders, etc. (equivalent of Linux symlinks) and not URL shortcuts." So I copy another folder and paste it as a shortcut in ../test, point the above script at that, and voila! Both approaches work
So does anyone know how I can get the URL out of a shortcut that contains one instead of another filesystem locaiton?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to get URL associated with an existing Windows URL shortcut?
by ikegami (Patriarch) on Aug 02, 2023 at 20:46 UTC | |
by cormanaz (Deacon) on Aug 03, 2023 at 14:14 UTC | |
by ikegami (Patriarch) on Aug 04, 2023 at 00:56 UTC | |
|
Re: How to get URL associated with an existing Windows URL shortcut?
by Discipulus (Canon) on Aug 03, 2023 at 09:19 UTC | |
by cormanaz (Deacon) on Aug 03, 2023 at 14:15 UTC | |
by NERDVANA (Priest) on Aug 04, 2023 at 20:57 UTC |