This is a VBS which can be used to create shortcuts to folders or files. CMD/Batch usually does not support creating shortcuts other than Symbolic links or Junctions. So you usually need external tools, but luckely VBS can create shortcuts and accept switches. Usage: Spoiler The script will accept 6 switches. The switches:Required: /target:"<Target>" /shortcut:"<Shortcut Name>" Optional: /parameters:"<Arguments for target>" /startin:"<Start in folder>" /description:"<Description>" /icon:"<Custom Icon>" If you pass parameters and need to use quotes, add a flower "\'/" to your argument. This will be replaced by a quote on parsing. You can execute the VBS from a script or from CMD. Code: CreateShortcut.vbs /target:"%WINDIR%\system32\cmd.exe" /parameters:"/C COLOR 1f & echo \'/By yours truly hearlywarlot :)\'/ & pause" /startin:"%~dp0" /shortcut:"Cmd to This Folder" /description:"Open CMD to this scripts directory" /icon:"%WINDIR%\explorer.exe" Edit this example command to suit your needs. Notes: Spoiler Since VBScript will not handle nicely quotes passed as string from CMD without making code ugly, I added \'/ as replacement which will turn to quotes on parsing. If you need these specific characters in arguments, change these characters in the VBScript to something else that will not bring you trouble. Code: Spoiler Filename: CreateShortcut.vbs Code: set WshShell = WScript.CreateObject("WScript.Shell" ) Set colNamedArguments = WScript.Arguments.Named iNumberOfArguments = WScript.Arguments.Count if iNumberOfArguments < 1 then Wscript.Echo "Switches:",vbCrLf,"/target:<Target>",vbCrLf,"/shortcut:<Shortcut Name>",vbCrLf,"/parameters:{Arguments for target}",vbCrLf,"/startin:{Start in folder}",vbCrLf,"/description:{Description}",vbCrLf,"/icon:{Custom Icon}" WScript.Quit 1 ElseIf Not colNamedArguments.Exists("target") Then Wscript.Echo "Switch /target:<Target> is missing." WScript.Quit 1 ElseIf Not colNamedArguments.Exists("shortcut") Then Wscript.Echo "Switch /shortcut:<Shortcut Name> is missing." WScript.Quit 1 End If set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named("shortcut") & ".lnk") oShellLink.TargetPath = Wscript.Arguments.Named("target") If colNamedArguments.Exists("parameters") Then arg = Wscript.Arguments.Named("parameters") oShellLink.Arguments = Replace(arg, "\'/", chr(34)) End If If colNamedArguments.Exists("startin") Then oShellLink.WorkingDirectory = Wscript.Arguments.Named("startin") End If If colNamedArguments.Exists("description") Then oShellLink.Description = Wscript.Arguments.Named("description") End If If colNamedArguments.Exists("icon") Then oShellLink.IconLocation = Wscript.Arguments.Named("icon") End If oShellLink.Save WScript.Quit
Or just nircmd.exe shortcut nircmd gets deployed on any machine i use or have to do with for a longer period.
I also like using NirCmd or practically any program from Nirsoft and I recommend it to anyone who need extra functions which cmd.exe does not support. But unfortunantly it is a external program which you usually would not find on Windows unless you add it yourself. So having a VBS which you can call or create from a script to make shortcuts is nice to have, since you know it will just work. My favorites are: BluescreenView, Produkey, Mail PassView, ShellExView, WhatIsHang, AlternateStreamView and HashMyFiles. You can also download all the programs from Nirsoft in a package with launcher called 'NirLauncher'.
Your wish has been fullfilled . You can now add arguments with the '/parameters' switch. If you need to use quotes, add a flower "\'/". This will be replaced by a quote on parsing. Strange as it may seem, VBScript will not handle nicely quotes passed as string from CMD without making code ugly. For reference and example look at my first post.