Power to Build

Home » Misc » Windows 7 – Symbolic Link

Windows 7 – Symbolic Link



I’ve started using Windows 7 machine. In spite of the quirks and changes, it “feels” nicer than Windows XP (probably because my XP machine is so old and my Office Software is from 2000!). As I am piloting the Powerbuilder upgrade project on this new Windows 7 machine, I stumbled on several issues; found some answers, some I am willing to live through.

One of the nicest features I love in Windows 7 are the links. It’s very similar to Unix links if you know about those. There are 3 types of links, Symbolic File links, Symbolic Directory links and Hard directory links.

Symbolic link is like the old Windows shortcuts, only better. The main difference is that shortcuts were a convenient way for us, humans, to point to something else that’s buried deep inside Windows file structure. Unfortunately, shortcuts were just files (have you ever opened a shortcut file? it’s file with .lnk type and contains some hard-coded information about the original file/folder it’s pointing to. Thus, Shortcuts were not recognized by any program as a proper replacement for the original path, because shortcut is, well, a totally different file as far as the program is concerned. This meant, the shortcuts were useless from developers’ point of view. See here for a terrific discussion of the differences between the two.

Symbolic links on the other hand are actual mapping in the file system table. This means, if you pass in the link’s path instead of the original path, OS will resolve the path to the original file/folder and pass it on to the program. This makes everybody happy.

If you create a shortcut and a symbolic link and do a DIR on command prompt, you will see the difference.

This really comes in handy. On Windows 7, all the 32-bit applications are typically installed inside “Program Files (x86)”. Some programs don’t link the special character in the path name. You could create a symbolic link to the program folder and use that to run it (change the shortcut accordingly).

Another good use I found was with the path setting. Since there is a limit on the length of the environment path setting, you could create a symbolic link with a shorter path to point to something that has a very long path, thus saving so precious bytes of the PATH setting, so you can squeeze in more programs into the system path.

During my PowerBuilder upgrade project I wanted to be able to keep both old (PB 10.2) and new (PB 12.5.2) versions of PB side by side, so I can switch back and forth. One could easily install the 2 versions in completely different locations, but with the shared EA Server, I wanted to separate only minimum set of files/folders and keep all the others shared between the 2 versions of PB in one location. Symbolic links came to the rescue. I created symbolic link to PB 10 and PB 12.5 versions of the directories and switch them using a batch file. More on this on a separate post.

How to create links


Creates a symbolic link.

MKLINK [[/D] | [/H] | [/J]] Link Target

/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.

/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.

The new command-line command mklink can be used to create Symbolic links. To create the Repository link in the above picture, I typed,

mklink /D c:\Sybase\EAServer\Repository   C:\Sybase\EAServer\Repository_125

Where Repository is the link and Repository_125 is the actual path it’s pointing to.

Now, I can CD into Repository and I will actually be in Repository_125.

C:\Sybase\EAServer>CD Repository

Volume in drive C has no label.

Directory of C:\Sybase\EAServer\Repository

11/15/2013 03:58 PM <DIR> .
11/15/2013 03:58 PM <DIR> ..

10/17/2013 10:41 AM <DIR> THIS_IS_REPOSITORY_PB125
10/17/2013 10:42 AM <DIR> WebApplication

Though the directory name is mentioned as C:Sybase\EAServer\Repository, I am actually inside Repository_125 now. Just so I know it’s actually PB 12.5 I created a folder to indicate that.


Note for Windows 7 Admin users

If you are using this command on Windows 7, then you will need to run the command using as Administrator. Otherwise, you will get the below error:

2014-07-18 15_43_43-Command Prompt

Note about running as Administrator: On Windows 7, unless you are using the default id Administrator, all your programs still run in normal mode, even if your id belongs to Administrator group. To be able to run a program as Administrator, you need to use “RunAsAdministrator” option. To do this, right click on the program and choose the option “RunAdAdministrator”. That’s all there is to it.

To run mklink in admin mode, you need to open the command prompt in admin mode first. To do this, you can find it in All Programs ->Accessories and right click to Run as Administrator.  See here. Any command you type within this shell, will be run in Admin mode.


1 Comment

  1. […] recently posted about symbolic links available in Windows 7. There I mentioned about how I used it to install PowerBuilder side by side. […]

Comments, please?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: