ProblemYou want to create a shortcut to a file or folder. A shortcut is simply a file with a .lnk extension that redirects you to another file or folder when clicked on in Windows Explorer. You can also distinguish shortcut files from regular files by a small arrow in the bottom left side of their icons. SolutionUsing a graphical user interface
Using downloadable softwareThe Windows NT Resource Kit had a tool called shortcut that could be used to create shortcuts, but it isn't present in the Windows 2000 or Windows Server 2003 Resource Kits. The MKS Toolkit (http://www.mkssoftware.com/products/tk/), an excellent product that provides numerous Unix-like utilities for the Windows platform, contains a shortcut tool, which can create shortcuts. Here is the syntax for that tool: > shortcut [-f dest-file] [-a arglist] [-w workdir] [-s show-keyword] [-i iconpath[,iconindex]] [-d description] [-D] shortcut-file -a arglist defines any arguments to the executable file specified with the -f dest-file option. -d description specifies descriptive text to be embedded in the link file. description is only displayed when you use the -p option to print the contents of the link file. If description includes space, the text should be enclosed in double quotes ("). -D shortcut-file specifies the shortcut-file is on the desktop. -f dest-file specifies the full path and file name of the executable file to be run when the link file is double clicked. -i iconpath[,iconindex] specifies the icon to be displayed for the link file. If the specified icon contains multiple images, determine which image is to be displayed by entering the appropriate number for iconindex. -p displays the contents of the specified shortcut file. -s show-keyword specifies how the executable is displayed when invoked. show-keyword can be one of the following: SW_SHOW starts the program in standard mode SW_SHOWMAXIMIZED starts the program in full screen mode SW_SHOWMINIMIZED starts the program minimized SW_SHOWMINNOACTIVE displays the program as an icon but does not start it When this option is not specified, shortcut defaults to SW_SHOW. -w workdir specifies the working directory in which the program is started. Here is an example: > shortcut -f c:/perl/bin/perl.exe -a -L perl-link.lnk
Using VBScript' This code creates a shortcut. set objWSHShell = CreateObject("WScript.Shell") ' Pass the path to the shortcut set 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 WScript.Echo "Shortcut to mylog created" ' This code finds all shortcuts on a system. ' ------ SCRIPT CONFIGURATION ------ strComputer = "." ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colSCs = objWMI.InstancesOf("Win32_ShortcutFile") for each objSC in colSCs WScript.Echo "Name: " & objSC.Name WScript.Echo "Target: " & objSC.Target WScript.Echo intCount = intCount + 1 next WScript.Echo "Total shortcuts: " & intCount DiscussionShortcuts can be used to quickly access files and folders that are distributed across the filesystem or on remote systems. The problem with shortcuts is that they can quickly become out-of-date if not maintained. There is a tool in the Resource Kit to help identify dead shortcuts called chklnks.exe. It searches for all shortcuts whose target does not exist and displays them in a list. You can right-click on a shortcut to see the missing target location or delete selected dead shortcuts. See AlsoMS KB 140443, "How to Create a Shortcut on the Desktop" |