Is it possible to create a shortcut from a .exe using batch scripting?
4 Answers
Yes it is possible to create a shortcut, sort of... you can create a .url file which works just like a shortcut (.lnk) file from at least windows 98 on up to currently Windows 7. The .url file which is actually used for the Windows Favorites bookmarks is a simple text file which references a url and some additional information. Here is a simple example of making one from a batch file:
@echo off
echo [InternetShortcut] >> Explorer.url
echo URL=C:\WINDOWS\EXPLORER.EXE >> Explorer.url
echo IconFile=C:\WINDOWS\EXPLORER.EXE >> Explorer.url
echo IconIndex=0 >> Explorer.url
Which results in a file named Explorer.url to be created with this content inside of it:
[InternetShortcut]
URL=C:\WINDOWS\EXPLORER.EXE
IconFile=C:\WINDOWS\EXPLORER.EXE
IconIndex=0
Double clicking on it will work just as a shortcut and run the program.

- 21
- 3
-
That will only work reliably as you describe if IE is set as the default application to open a URL, which should never be assumed. – John Gardeniers Oct 28 '10 at 02:14
-
Works regardless of whether or not IE is set as the default application to open a URL. I have used this form of shortcut since Windows 98 and have never had IE set as the default application to open a URL. – Garrett R. Hylltun Oct 28 '10 at 02:34
-
If you notice, the association for .url in the registry points to rundll with and IE component as a parameter to the rundll. So, it's independent of whether IE is set to use .url files, but does require IE to be part of the system, which pretty much covers over 99%(uneducated estimate) of all Windows based PCs. Point is, likely only very deep computer users might be running without IE installed as part of their system and possibly some people in Europe who do not select IE as their browser when installing Windows since the mandatory selection screen. – Garrett R. Hylltun Oct 28 '10 at 02:46
Using batch alone? Probably not, unless you're just copying a shortcut from the Start Menu to somewhere else. We had this issue when building/refining our latest deployment process and certain groups wanted shortcuts to everything on their desktop.
The Windows NT Resource Kit has a utility named shortcut.exe
that could do this. I have never tested it on XP/2003/2008.
If you can get away with VBS, this would work:
Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = "C:\MyShortcut.LNK"
Set oLink = oWS.CreateShortcut(sLinkFile)
oLink.TargetPath = "C:\Program Files\MyApp\MyProgram.EXE"
' optional shortcut properties
' oLink.Arguments = ""
' oLink.Description = "MyProgram"
' oLink.HotKey = "ALT+CTRL+F"
' oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2"
' oLink.WindowStyle = "1"
' oLink.WorkingDirectory = "C:\Program Files\MyApp"
oLink.Save

- 24,484
- 8
- 79
- 100
I think there's no way to create a batch file direct from a batch file, maybe you could write in the windows registry from bat or if you dont bother in using a third party app in this job, you can download shortcut.exe (www.optimumx.com) and call it in a bat. shortcut.exe /f:"%AllUsersProfile%\desktop\ShortcutName.pif" /a:c /t:folder:\MyApp ... i/image.icon.....

- 3,180
- 6
- 29
- 37
Have you considered using Symbolic links? This maybe the closest alternative you can get. 1. Only Administrators can create symbolic links. 2. Requires VISTA or Higher OS with NTFS.
The utilities used to create them are built-in: MKLINK.exe and/or LINKD.exe and can be easily scripted in a batch file.

- 161
- 2
- 6