Create Shortcut File (LNK) via command line

Hello Experts,

I am seeking for a tool that lets me create a Windows shortcut file (.lnk) file from within a batch file or via command line.

Additional reqired features:

* must work on Windows 9x and Windows NT.

* must be as small as possible, since intended use is Logon-Scripts over slow RAS links, so no libraries, VB runtimes, Scripting host, ect, just one standalone .exe file.

* parameter passing either via environment variables or plain text file (ini file), since the tools command line very likely cannot hold enough characters to specify all aspects of a lnk file.

Just to make everything clear, a sample of how I'd like to create a link:

Set title=Edit-a-file
set exefile=c:\winnt\system32\notepad.exe
set workdir=c:\temp
more set statements to define the lnk file symbol, shortcut key, ...

makelnk "c:\winnt\profiles\all users\desktop\Notepad.lnk"

So who can help me to get such a program "mklink.exe" ...?

P.S. somewhere I found a hint how to create a lnk file via DDE. Unfortunately the author didn't give any details (just said it was possible), and didn't cover the topic how to send DDE commands from the command line (probably a tool is available somewhere). I would accept such a solution as well, if the DDE sender tool is pretty small...


Who is Participating?
simonetConnect With a Mentor Commented:
I have rewritten the application and tested it. Everything should be ok now.

Please re-download it from the link I gave you in my first comment: 

sorry for the delay.


Why can't you:
Make the link on your local machine, set theproperties as yo0u like them, and just transfer the created .lnk file to the user's desktop.  I think this will work for you.  These files are less than 1k in size.
The problem with that is that the newer LNK files carry full path info (including server name) with them.

LNKs that will reside on C and refer only to C will be just fine with that approach.

Have you tried SHORTCUT.EXE from the NT4 Resource Kit:

shortcut: [-? -h -f -c -r -s] [[-t] target [[-n] name]] [-d working
        [-a Arguments] [-i Iconfile] [-x Icon index] [-u {all|[natdix]}]
        [-l logfile]

  -? -h This help
  -f Force overwrite of an existing short cut
  -c Change existing shortcut
  -s Make shortcut non tracking (Stupid)
  -r Resolve broken shortcut
  -t target Specifies the target of the shortcut
  -n name Specifies the file name of the shortcut file
  -d directory Specifies the directory name to start the application in
  -a arguments Specifies the arguments passed when the shortcut is used
  -i iconfile Specifiles the file the icon is in
  -x index Specifies the index into the icon file
  -u [spec] Dumps the contents of a shortcut. 'all' is the same as
               but the letters of 'natdix' can be specified to display
               fields in the shortcut (repeats allowed, and order
  -l logfile record error messages in specified file

Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

arminlAuthor Commented:
simply lack of flexibility.

the UNC path in the link is not an issue, it can be fixed setting the LinkResolveIgnoreLinkinfo policy.

I also have knowledge of shortcut.exe, but

a) it does not work with Windows 9x (but there is another program named shortcut.exe in the Windows 95 resource kit that works for 98 as well, but not for NT .-()
b) I searched all of the disks in my Technet Subscription, especially the various Resource Kits, but there was no shortcut.exe program :-(

Rumours say there is another NT Resource Kit CD called "supplemental two" which must be ordered separately from Microsoft, but I haven't verified this yet.


I have written a program that does what you need. It's function is pretty much the same of SHORTCUT.EXE.

It's free and can be downloaded from here:

Documentation is enclosed in the ZIP file.



By the way, MAKELNK meets all your requirements: it's small, does the job, is a simple standalone EXE (requires no other files to work), works with Win95/98/NT/2000.


arminlAuthor Commented:
Hi Alex,

the program looks promising. Tested it on WNT, W2000, and W98. Links are created in several directories:

1  desktop (OK)
2  Favorites (OK)
3  Program Files (OK)
4  Start Menu (OK)
5  Autostart (not corresponding with doc)
6  (hangs)
7  Appdata (not corresponding with doc)

The line I used to test was:

makelnk /T "%windir%\poledit.exe" /D "Test Link" /L 1 /G "Testgroup"

I increased /L by one and started the line 7 times.

A Testgroup never was created anywhere. Do you have a sample at hand how to create a groiup?

All Icons are put in the user profile directories. How can I create links in "all users" and "default user" profile directories?


I'll take a look at it and get back to you.


arminlAuthor Commented:
I have also tried to get "shortcut.exe" for nt, and bought the Windows NT Workstation Resource Kit SUpplement 4, which is the latest issue of the Resource kit (I was told).

A shortcut.exe for NT is not contained in that package.

So where do I get it ...?

Have you thought of using "Windows Scripting" (JavaScript, VBScript)... there is a method in the WSHShell Object for creating shortcuts.

Extract from WSHOBJ.DOCW

The CreateShortcut method creates a WshShortcut object and returns it. If the shortcut title ends with ".URL," a WshURLShortcut object is created.
WshShell.CreateShortcut(strPathname) = objShortcut
' This code fragment creates a shortcut
' to the currently executing script
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set oShellLink = WshShell.CreateShortcut("Current Script.lnk")
oShellLink.TargetPath = Wscript.ScriptFullName
Set oUrlLink = WshShell.CreateShortcut("Microsoft Web Site.URL")
oUrlLink.TargetPath = ""
See Also
WshShortcut object, WshUrlShortcut object

hope this helps


The folks in Redmond CLAIM it's on the NT4 Server and Workstation Resource Kits as well as the 95 Resource Kit.

I found it on the 95 CD, but could only find the WSH script on the Sep 99 NT utilities CD.
arminlAuthor Commented:
Whs is not installed on any machine, and what I am after is just a standalone .exe.

Simonets exe looked really promising and has worked pretty good in some way, so if he manages to get the group things right that's exactly what I am after.

Regarding the Redmond folks: I guess that the program is on the Ressource Kit Supplemental 2 only.

arminlAuthor Commented:
Answer accepted
arminlAuthor Commented:
While alex program still does show some unexpected behavior when it comes to create a shortcut where I want it it does at least create a shortcut, and I can always move it where I need it. Wrinting a piece of software deserves an "excellent" ranking though.

All Courses

From novice to tech pro — start learning today.