in reply to How to get URL associated with an existing Windows URL shortcut?

Works for me.

use v5.14; use warnings; use Win32::OLE qw( ); my $wsh = Win32::OLE->new( 'WScript.Shell' ); sub read_shortcut { my $lnk_path = shift; my $shcut = $wsh->CreateShortcut( $lnk_path ) or die; return $shcut->TargetPath; } say read_shortcut( "a.url" );
>perl a.pl https://www.perlmonks.org/

Are you sure you have the right file name?

Replies are listed 'Best First'.
Re^2: How to get URL associated with an existing Windows URL shortcut?
by cormanaz (Deacon) on Aug 03, 2023 at 14:14 UTC
    Maybe it has something to do with the extension on the shortcut? When windows creates the shortcut it doesn't supply any extension. When I add an extension .url it still doesn't work. And yes I am giving the full path. Go figure!

    EDIT: Well, well...I read the directory and Perl says the shortcut file has extension .url. In File Explorer no extension is shown *even though I have it configured to show extensions* and it shows them for other files. Microsoft trying to "help" me again! :-/

      yeah, extensions of shortcuts have always been hidden, regardless of that setting.