Create a shortcut (Perl)

This code can be found in Chapter 8 of Windows XP Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# From the book "Windows XP Cookbook"
# ISBN: 0596007256

use Win32::OLE;

$objWSHShell = Win32::OLE->new('WScript.Shell');

# Pass the path to the shortcut
$objSC = $objWSHShell->CreateShortcut('d:\\mylog.lnk');

# Description - Description of the shortcut
$objSC->{Description} = 'Shortcut to MyLog file';

# HotKey - hot key sequence to launch the shortcut
$objSC->{HotKey} = 'CTRL+ALT+SHIFT+X';

# IconLocation - Path of icon to use for the shortcut file
$objSC->{IconLocation} = 'notepad.exe, 0';
# 0 is the index

# TargetPath = Path to source file or folder
$objSC->{TargetPath} = 'c:\\windows\\notepad.exe';

# Arguments - Any additional parameters to pass to TargetPath
$objSC->{Arguments} = 'c:\\mylog.txt';

# WindowStyle - Type of window to create
$objSC->{WindowStyle} = 1;
# 1 = normal; 3 = maximize window; 7 = minimize

# WorkingDirectory - Location of the working directory for the source app
$objSC->{WorkingDirectory} = 'c:\\';
$objSC->Save();
print "Shortcut to mylog created\n";

This code has been viewed 1156 times.

New from the creators of TechTasks.com: StatSheet.com