http://www.perlmonks.org?node_id=283496

Here's how to create a Windows shortcut, including some handy constants for building up a hotkey. Thanks to Foggy Bottoms for the starting point, I just enumerated the metakey codes through experimentation.

Amended: use constant
Amended: pick up USERPROFILE

use constant SHIFT => 0x0100; use constant CTRL => 0x0200; use constant ALT => 0x0400; my $LINK=new Win32::Shortcut(); $LINK->Set('c:\targetfile', '', # arguements 'c:\', # directory tto execute in 'Perl Shortcut', # description 1, # window state (1 is normal) SHIFT+CTRL+ord('S'), # shorcut key '', # icon file eg win32.dll 0); # icon number in file my $shortfile = $ENV{USERPROFILE}.'\Start Menu\Programs\Acces +sories\shortcut.lnk'; $LINK->Save($shortfile); # run Explorer targetting the file just created # system("Explorer /e,/select,$shortfile"); $LINK->Close();

Replies are listed 'Best First'.
Re: Creating a Windows shortcut file
by Brutha (Friar) on Aug 14, 2003 at 13:22 UTC
    Thank you Phill for writing it down.

    For those of you, who love named parameters, you could write:

    $LINK->{'Path'} = 'C:\PERL\BIN\WPERL.EXE'; # ActiveState $LINK->{'Arguments'} = $path_of_perl_script; $LINK->{'WorkingDirectory'}= "$ENV{HOME}"; # if exists $LINK->{'Description'} = "Perl Shortcut"; $LINK->{'ShowCmd'} = SW_SHOWNORMAL; $LINK->{'IconLocation'} = 'Camel.ico'; # insert your path ... if (-e $shortfile) { ... } # created ?
    etc.

    And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
    (Terry Pratchett, Small Gods)