views:

1832

answers:

9

EDIT!

Sorry to change the question on everyone, but I am really just asking:

How do I create a shortcut (.LNK) file from the command line with as little outside help as possible? I really don't want to run a VBscript or to download a program to do it for me. Is it really that hard?

Thanks to everyone who provided exceptional answers when I didn't really know what I was asking yet!


The original title of this question was:

Windows equivalent of Unix ln -s for creating shortcuts from the command line?

The original question text of this question was:

On *nix, I can create a symbolic link to a file very easily from the command line using ln -s.

How do I natively create a shortcut to a file using the Windows XP command prompt?

Note: This is not the approach I want to take. I want to do it the way Windows does it. I want to do it the right way.

+2  A: 

http://www.ss64.com/nt/shortcut.html EDIT: Sorry I deleted that. .. but that is an old NT command ... don't know if it active on XP.

rupert0
+1  A: 

I have a file called shortcut.exe on my system. Honestly, I have no idea where I got it. :-( But a quick search came up with the following website:

http://www.optimumx.com/download/#Shortcut

Maybe that will work for you?

Dana
+4  A: 

XP doesn't have symlinks. On Vista, the command is mklink. Shortcuts are not symlinks.

Paul Betts
What is the difference?
eleven81
shortcuts are files. symlinks are a different construct. There really is no comparison
cbrulak
Shortcuts are a file that Explorer knows how to parse; if I open a shortcut to a text file with Notepad, I get nonsense, not the text file the shortcut points to
Paul Betts
Thank you, Paul Betts!
eleven81
In UNIX, symbolic links act equivalently to the item they link to unless you specifically request different behavior. Windows shortcuts are not parsed in the file system layer, but in Explorer itself. Thus, many programs *cannot* follow shortcuts.
Eddie
XP *does* have symlinks, it's build into NTFS. That Microsoft chose not to expose this functionality says volumes IMO. See http://elsdoerfer.name/=ntfslink for more information and an interface to create them.
Matthew Scharley
@Matt, hard links != symlinks != junction points; hard links are completely different, junction points are similar but can't point to another filesystem (they have to point to something else in the same NTFS volume)
Paul Betts
+2  A: 

mklink link target

Unfortunately, this only works on Vista/Server 2008 or newer.

R. Bemrose
+4  A: 

This is not a native Windows call, but you should probably look into Windows Sysinternals' Junction. This is a very handy tool of good quality.

If you don't want to rely on external software, you should look at kb205524 for native ways of creating junction points.

Magnus Akselvoll
+1  A: 

Softlinks are supported by the file system used by windows.
Though this functionality is not exposed by any standard windows tools.

There are opensource tools available that can do the trick though.

Martin York
+2  A: 

Actually NTFS does support symbolic links. See Wikipedia NTFS_symbolic_link

sig11
Yes, but only in Vista. Junction points and reparse points can sometimes mimic symlinks but aren't as flexible
Paul Betts
The very first paragraph in that Wikipedia article states "were introduced with the modifications made to the NTFS file system with Windows Vista". The question was about XP.
Mark Ransom
Sorry, I had to leave for a meeting and hit save before completing the thought. I misremembered hard link support in 200+ and Patrick Cuff hit it right on the head. What's the etiquette? delete?
sig11
+6  A: 

Windows XP and later has the fsutil command, which can create "hardlinks" to files.

See:

Patrick Cuff
+1  A: 

Everyone seems to be beating around this bush, but I haven't seen anyone actually come out and say it yet: NTFS supports something called "junction points", which are very similar, though slightly less useful than, symlinks. These are different than both shortcuts and hard links. I use them regularly for building different versions of our software at the same location on my system (just repoint the build directory link to a different SVN checkout). The tool I use for this is called ntfslink. That page also contains a pretty good explanation of how NTFS junction points work and which versions of Windows support which features. I use it on Win Server 2k3. The ntfslink program is a shell extension, but there are other similar utilities that work from the command line. There are also Windows API functions available to create them if you want to do it programmatically from whatever app you're developing.

rmeador