Adding Command-Line Switches To Windows Shortcuts

43,538

Solution 1

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

Solution 2

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.

Solution 3

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.

Share:
43,538

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    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?

    • Admin
      Admin over 12 years
      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".
    • Vadzim
      Vadzim almost 9 years
      Dup of superuser.com/questions/29569/…. Intermediate bat/cmd file is not necessary.
  • Admin
    Admin over 12 years
    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.