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?

  • 1
    If you want to pass command line switches, you must also pass the application. Because who knows, maybe *.xlsx files are handled by some non-Excel application where the /r switch means "reformat hard drive".
    – Raymond Chen
    Nov 15 '11 at 21:28
  • Dup of superuser.com/questions/29569/…. Intermediate bat/cmd file is not necessary.
    – Vadzim
    Jun 22 '15 at 12:31

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

  • 1
    Grumble, Win 7 still doesn't have basic features that OS/2 had twenty years ago. Off to create a pointless one line batch file. Sep 28 '14 at 14:36

Your shortcut should contain the full path to both the executable and the target file, like this:

"C:\Program Files\Microsoft Office\Office12\EXCEL.EXE" /r "C:\Users\Administrator\Desktop\abc.xlsx"

Note that both EXE and XLS paths are in quotes to avoid problems with spaces in the name.


Target is the field to change. But since a shortcut points to a path two shortcuts to the same file may contain different target depending on how the network drives are mapped. So generally, you can't copy a shortcut over the network and hope it will work, since the target might no longer be valid.

  • Ok, let me phrase this differently. I want to create a shortcut to abc.xlsx that opens abc.xlsx as read-only. If I create the shortcut mentioned in my original post, it opens a new instance of Excel 2007 that isn't grouped with existing open Excel files. Thus I would like the same behaviour as when I double-click abc.xlsx in Explorer, but with Windows passing the '/r' command line switch. This has nothing to do with networking.
    – jaytea
    Nov 8 '11 at 7:40

You could define an environment variable to Office's directory and use this variable in your shortcut. Of course, this variable will have to be define on every computer of your network, but it can be done through a script and it can be use for other purpose in the future.

If you define an environment variable named Office, you can create a shortcut as so :

cmd /c ""%Office%\EXCEL.EXE" /r "abc.xlsx""

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy