How to Create Symbolic Links
By default, only administrators can create symbolic links. However, you can grant other users access using the Computer Configuration\Windows Settings\Security Settings\Local Policies \User Rights Assignment\Create Symbolic Links setting.
To create a symbolic link, open a command prompt with administrative privileges and use the mklink command. For example, the following command creates a symbolic link from C:\Myapp.exe to Notepad in the system directory.
C:\>mklink myapp.exe %windir%\system32\notepad.exe
Symbolic link created for myapp.exe <<===>> C:\Windows\system32\notepad.exe
Note Developers can call the CreateSymbolicLink function to create symbolic links. For more information, go to http://msdn.microsoft.com/en-us/library/aa363866.aspx.
After you create this symbolic link, the Myapp.exe link behaves exactly like a copy of the Notepad.exe file. Windows Explorer displays symbolic links using the standard shortcut symbol. However, shortcuts always have a .lnk extension, whereas symbolic links can have any extension. At a command prompt, the dir command uses the <SYMLINK> identifier to distinguish symbolic links and displays the path to the target file.
C:\>dir Volume in drive C has no label. Volume Serial Number is BC33-D7AC Directory of C:\ 09/18/2006 04:43 PM 24 AUTOEXEC.BAT 09/18/2006 04:43 PM 10 config.sys 12/27/2006 12:16 PM <SYMLINK> myapp.exe [C:\Windows\system32\notepad.exe] 12/23/2006 04:47 PM <DIRglt; Program Files 11/29/2006 03:31 PM <DIR> Users 12/27/2006 08:39 AM <DIR> Windows
Because a symbolic link is only a link, any changes made to the link actually affect the target file and vice versa. If you create a symbolic link and then delete the target file, the symbolic link will remain, but any attempts to access it will return a File Not Found error because Windows will attempt to access the link target automatically. If you delete a target file and later replace it with a file of the same name, that new file will become the link target. Deleting a link does not affect the link target. Attribute changes to the symbolic link, such as marking a file as hidden or as a system file, are applied to both the symbolic link and the target file.
How to Create Relative or Absolute Symbolic Links
Relative symbolic links identify the location of the target based on their own folder. For example, a relative symbolic link to a target file in the same folder will always attempt to access a target with the specified filename in the same folder, even if the symbolic link is moved. You can create relative or absolute symbolic links, but all symbolic links are relative by default. For example, consider the following commands, which attempt to create a symbolic link named Link.txt to a file named Target.txt and then attempt to access the symbolic link before and after moving the target file.
C:\>mklink link.txt target.txt C:\>type link.txt Hello, world. C:\>REM Move link.txt to a different folder C:\>move link.txt C:\links 1 file(s) moved. C:\>cd links C:\links>type link.txt The system cannot find the file specified. C:\links>move \target.txt C:\links C:\links>type link.txt Hello, world.
In the previous example, moving the symbolic link to a different folder causes Windows to be unable to locate the target because the symbolic link is a relative link pointing to a file named Target.txt in the same folder. When both the link and the target are moved to the same folder, the symbolic link works again.
Now consider the same example using an absolute symbolic link, created by specifying the full path to the target file:
C:\>mklink link.txt C:\target.txt C:\>type link.txt Hello, world. C:\>REM Move link.txt to a different folder C:\>move link.txt C:\links 1 file(s) moved. C:\>cd links C:\links>type link.txt Hello, world. C:\links>move C:\target.txt C:\links\ C:\links>type link.txt The system cannot find the file specified.
In the last example, specifying the full path to the target file creates an absolute symbolic link that references the full path to the target file. Therefore, the symbolic link still works after it is moved to a different folder. However, moving the target file makes it inaccessible.
In this tutorial:
- Managing Disks and File Systems
- Overview of Partitioning Disks
- How to Choose Between MBR or GPT
- Converting from MBR to GPT Disks
- GPT Partitions
- Choosing Basic or Dynamic Disks
- Working with Volumes
- How to Create a Simple Volume
- How to Create a Spanned Volume
- How to Create a Striped Volume
- How to Resize a Volume
- How to Delete a Volume
- How to Create and Use a Virtual Hard Disk
- File System Fragmentation
- Backup And Restore
- How File Backups Work
- File and Folder Backup Structure
- How System Image Backups Work
- How to Start a System Image Backup from the Command Line
- How to Restore a System Image Backup
- System Image Backup Structure
- Best Practices for Computer Backups
- How to Manage Backup Using Group Policy Settings
- Previous Versions and Shadow Copies
- How to Manage Shadow Copies
- How to Restore a File with Previous Versions
- How to Configure Previous Versions with Group Policy Settings
- Windows ReadyBoost
- BitLocker Drive Encryption
- How BitLocker Encrypts Data
- How BitLocker Protects Data
- TPM with External Key (Require Startup USB Key At Every Startup)
- TPM with PIN (Require PIN At Every Startup)
- TPM with PIN and External Key
- BitLocker To Go
- BitLocker Phases
- Requirements for Protecting the System Volume with BitLocker
- How to Enable the Use of BitLocker on the System Volume on Computers Without TPM
- How to Enable BitLocker Encryption on System Volumes
- How to Enable BitLocker Encryption on Data Volumes
- How to Manage BitLocker Keys on a Local Computer
- How to Manage BitLocker from the Command Line
- How to Recover Data Protected by BitLocker
- How to Disable or Remove BitLocker Drive Encryption
- How to Decommission a BitLocker Drive Permanently
- How to Prepare AD DS for BitLocker
- How to Configure a Data Recovery Agent
- How to Manage BitLocker with Group Policy
- The Costs of BitLocker
- Windows 7 Encrypting File System
- How to Export Personal Certificates
- How to Import Personal Certificates
- How to Grant Users Access to an Encrypted File
- Symbolic Links
- How to Create Symbolic Links
- How to Create Relative or Absolute Symbolic Links
- How to Create Symbolic Links to Shared Folders
- How to Use Hard Links
- Disk Quotas
- How to Configure Disk Quotas on a Single Computer
- How to Configure Disk Quotas from a Command Prompt
- How to Configure Disk Quotas by Using Group Policy Settings
- Disk Tools
- MoveFile and PendMoves