Windows – Adding Command-Line Switches To Windows Shortcuts

shortcutswindows

Is there a way to, in general, create a Windows shortcut to a file and instruct Windows to pass certain switches to the application before passing the filename?

For example: I have an Excel file, abc.xlsx. If I want to create a shortcut to open this file read-only, I would change the target to "C:\Program Files\Microsoft Office\Office12\EXCEL.EXE" /r abc.xlsx, but this fails when another person on my network opens the shortcut and their EXCEL.EXE is not in that same folder.

Surely there's a way to tell Windows to pass the /r switch without supplying the path/filename of the application that is supposed to open the file?

Best Answer

Use a batch (cmd/bat) file for this purpose. Do not create a shortcut to Excel, but rather create a shortcut to your batch file.  This file will have the necessary logic.  Look at the example image, which is VS.NET command prompt which uses same bat file with parameters.

  1. Find the correct path for Excel, if it is not in path *
  2. use /r
  3. use the correct Excel file name.

* Because the location of Excel may vary from machine to machine, it may be helpful to use start excel "c:\myfile.xls" /r within your batch file.  start excel should initiate Excel regardless of its location.

VS.NET Command Prompt Example