Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Creating a Windows shortcut file

by PhilHibbs (Hermit)
on Aug 13, 2003 at 09:29 UTC ( #283496=snippet: print w/replies, xml ) Need Help??
Description: 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();
           '',                  # 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
# run Explorer targetting the file just created
# system("Explorer /e,/select,$shortfile");
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 ?

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://283496]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2020-10-28 23:31 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (265 votes). Check out past polls.