12

I have a Windows application that I need to invoke with a desktop shortcut and some command-line parameters.

I've done this thousands of times, but this one is a bit different. Instead of using a normal command-line parameter like -e 12345 or -example 12345, this one uses @12345 (starting with the @ symbol).

Windows shortcuts do not like this parameter coming immediately after the executable name, and it just strips everything out. I don't know why.

For example:

c:\example\example.exe @12345 -e9876 as the "target", when saving, strips out all the parameters and leaves just c:\example\example.exe as the target.

But c:\example\example.exe -e9876 @12345 works just fine. It saves, and validates, and everything is good.

However I need the @ parameter to be the first one on the command. Apart from doing something like wrapping the command in a batch file and calling the batch, how can I have an @ symbol be the first command line parameter on a Windows shortcut?

Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
  • 1
    The other option is to quote the params (individually), assuming said program supports that. Interesting behaviour I just found on testing, though: the params are gone from the Target field *but* they're still passed to the target program! In fact, the now-invisible params are preserved until you edit the field again, and the `.lnk` files are actually different. (Tested with the target as a batch file that simply echoes the params passed in.) – Bob Jul 02 '15 at 01:52

1 Answers1

13

Who knew? ... Windows apparently treats the @ character as a delimiter. Windows commands will only interpret the first element in the command... so it effectively truncates the rest. Apparently, you can override the behavior by supplying a ^ before it to escape the symbol.

i.e.

c:\example\example.exe ^@12345 -e9876

TheCompWiz
  • 7,349
  • 16
  • 23
  • 3
    Hey! It works! Out of curiosity, how on earth did you find the answer to that? – Mark Henderson Jul 01 '15 at 23:08
  • 3
    Deeeep dark postings of yester-years. Some person made reference to documents that don't exist anymore (or at least not easy to find) and mentioned some of those tidbits. He also mentioned things like the `$` and `%` characters that can cause other issues. You can escape those using the same `^` character. You can also escape the escape by doing `^^` as you might expect. – TheCompWiz Jul 01 '15 at 23:10
  • 4
    @MarkHenderson The Caret symbol "^" is the standard "escape the next character" symbol used by then entire WIN32 (and later 64-bit) API since (if I recall correctly) at least NT 3.5 (yes: I'm getting old). It works in just about any place in Windows where you can supply a command-line: CMD-scripts/prompt, WIndows+R run box, short-cuts, in the command-lines associated with services and scheduled tasks, just to name a few. – Tonny Jul 02 '15 at 09:19