Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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();
$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();
Comment on Creating a Windows shortcut file
Download Code
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)

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2015-07-01 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (12 votes), past polls