how to create a shortcut for a exe from a batch file.
i tried
call link.bat "c:\program Files\App1\program1.exe" "C:\Documents and Settings\%USERNAME%\Desktop" "C:\Documents and Settings\%USERNAME%\Start Menu\Programs" "Program1 shortcut"
but it did not worked.
link.bat can be found at http://www.robvanderwoude.com/amb_shortcuts.html
The simplest way to create a desktop shortcut for your favorite program is to right-click on its .exe file and select Send To > Desktop (Create shortcut). You will see that its shortcut has been created on your Windows desktop. If you instead select Create shortcut, its shortcut will be created in the same location.
Create a Shortcut and Point It to the Batch FileRight-click the desktop and select New > Shortcut. Choose a location, ideally the same as your batch file, and click Next. Then enter a name for the shortcut and click Finish.
Create Batch File to Run EXESave your file with the file extension . bat , e.g. run-exe-program. bat and double click on it to run the .exe program.
Make sure you have your BAT file ready and move it to a folder. Run BAT 2 EXE and in the GUI that opens alongside the Command Prompt window, select the folder that the batch file you want to convert to EXE is in. Next, select where you want to save the EXE that will be created.
Your link points to a Windows 95/98 version and I guess you have at least Windows 2000 or XP. You should try the NT version here.
Alternatively use a little VBScript that you can call from the command line:
set objWSHShell = CreateObject("WScript.Shell") set objFso = CreateObject("Scripting.FileSystemObject") ' command line arguments ' TODO: error checking sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0)) sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1)) sWorkingDirectory = objFso.GetAbsolutePathName(sShortcut) set objSC = objWSHShell.CreateShortcut(sShortcut) objSC.TargetPath = sTargetPath objSC.WorkingDirectory = sWorkingDirectory objSC.Save
Save the file as createLink.vbs and call it like this to get what you originally tried:
cscript createLink.vbs "C:\Documents and Settings\%USERNAME%\Desktop\Program1 shortcut.lnk" "c:\program Files\App1\program1.exe" cscript createLink.vbs "C:\Documents and Settings\%USERNAME%\Start Menu\Programs\Program1 shortcut.lnk" "c:\program Files\App1\program1.exe"
That said I urge you not to use hardcoded paths like "Start Menu" since they're different in localized versions of windows. Modify the script instead to use special folders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With