Solved Creating a working shortcut file (.lnk) with batch

Hewlett-packard / Pavilion hpe
December 21, 2013 at 07:16:27
Specs: Windows 7 Home Premium, 3.4GHz 12GB
I'm working on a small batch installer, which I need to be able to create shortcut files. Is this possible with batch, or do I just have to work around them?

If infinity is infinite, is the square root of infinity infinite as well?
- Kurp Von Steiner

See More: Creating a working shortcut file (.lnk) with batch

Report •

December 21, 2013 at 08:34:22
::====== script starts here ===============
:: mlink.bat 2013-12-21 23:24:13.18
@echo off & setLocal enableDELAYedeXpansioN

if %1'==' echo what site && goto :eof

> "%*.URL" echo.[InternetShortcut]
>> "%*.URL" echo.URL=http://www.%*/index.html
goto :eof
goto :eof
::====== script ends here =================

M2 Golden-Triangle

Report •

December 21, 2013 at 16:52:25
✔ Best Answer
As far as programmatic, or executable links (shortcuts), no, batch can't create them because they contain binary information. You could use VBscript or a compileable programming language to access the object, or you could "cheat" and write a batch-file link directly to the desktop (but it will have the old "cog-and-gear" batch icon).
F/e, to launch an executable, Notepad, your batch just has:
@start \windows\system32\notepad.exe

Here's vbscript (courtesy of microsoft, comments etc. removed)
'====== begin vbscript SHORTCUT.VBS
Set WSHShell = WScript.CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
'create blank shortcut link
Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\Shortcut to notepad.lnk")

' Set shortcut object properties and save it
MyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings("%windir%\notepad.exe")
MyShortcut.WorkingDirectory = WSHShell.ExpandEnvironmentStrings("%windir%")
MyShortcut.WindowStyle = 4
MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings("%windir%\notepad.exe, 0")
'========= END VBSCRIPT
You would of course make replaceable parameters instead of hard-code, and your installer would invoke the script with the desired settings on commandline:
CSCRIPT SHORTCUT.VBS caption target working winstyle icon

message edited by nbrane

Report •

Related Solutions

Ask Question