Windows – Create a Windows shortcut through a batch file (.bat)

batch-filescriptingwindows

Is it possible to create a shortcut from a .exe using batch scripting?

Best Answer

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

Source