Recipe 4.7. Creating a Link or Junction Point
You want to create a link to a folder. This is sometimes referred to as a junction point. Links can be created only on NTFS file systems. Junction points are useful if you want to create a simplified
Using a command-line interface
The linkd.exe command from the Resource Kit can create a link:
> linkd <LinkName> <Target>
This creates a link from folder c:\program files\perl to c:\perl :
> linkd c:\perl "c:\program files\perl"
linkd c:\perl /d
You can also use the Sysinternals junction.exe tool to create and delete links:
> junction c:\perl "c:\program files\perl" > junction /d c:\perl
A cool thing about junction.exe is that you can also use it to search for links:
> junction /s c:\
If you are browsing the file system with Windows Explorer, you won't be able to differentiate links from normal files and folders, but in a CMD session you can. A link shows up as <JUNCTION> , as shown here:
> dir Volume in drive C is System Volume Serial Number is F0CE-2C6F Directory of C:\ 01/02/2002 09:08 AM 0 build.ini 10/06/2003 01:57 PM <DIR> Documents and Settings 11/02/2003 12:01 AM <DIR> Inetpub 11/18/2003 11:43 PM <JUNCTION> Perl 10/06/2003 02:14 PM <DIR> Program Files 11/16/2003 11:25 PM <DIR> scripts 12/04/2003 12:45 AM <DIR> WINDOWS 6 File(s) 439,283,427 bytes 7 Dir(s) 1,575,822,336 bytes free
' This code creates a link by shelling out to the linkd command. ' ------ SCRIPT CONFIGURATION ------ strLink = "c:\perl" strTarget = "c:\program files\perl" ' ------ END CONFIGURATION --------- strCommand = "linkd " & strLink & " " & strTarget set objWshShell = WScript.CreateObject("WScript.Shell") intRC = objWshShell.Run(strCommand, 0, TRUE) if intRC <> 0 then WScript.Echo "Error returned from running the command: " & intRC else WScript.Echo "Command executed successfully" end if
Links, or junction points, are different from shortcuts in that they are transparent to any process or application that
MS KB 205524 (How to create and manipulate NTFS junction points)
Recipe 4.8. Creating a Program Alias
You want to create a program alias for an application or commonly accessed file. A program alias is a little different from a shortcut or link. It is similar in function to the
command common on most Unix platforms. The alias name can be used as an alternative to typing the full program
The following is how you'd create the cmp alias I just described.
Create a new
The name of the subkey should be the alias name. So you don't have to type an extension when using the alias, put
at the end of the name. In this case, the subkey name would be
. You can, in fact, call the alias anything you want, but if the alias extension is not an executable extension such as
, you'll have to type the complete alias name when calling it. So it is
Next, modify the default value under the new subkey; it shows up with the name
in Registry Editor. Enter the full
Now you'll be able to run cmp from the Run dialog. From a command prompt, you can't just type cmp and have it launch the program. Instead you need to type start cmp , which will do the trick.
There are a couple of things to keep in mind when entering the path to the program in the value under the subkey:
You can force the program to start in a particular directory by creating a Path value under the alias subkey. Create a REG_SZ value entry named Path , and for its value put the full path to the directory where the program should start in.