39

We came with a scenario where we have to use Shortcut file (.lnk), which is on the desktop, to execute an application for a headless device (i.e, without manual intervention).

Is there any way to execute it from Command prompt?

6 Answers 6

29

If you use double quotes around your "long file names.lnk" and you have appropriate privileges, it will execute. Quotes are needed when spaces exist in LFN's.

E.g. "C:\Users\Sunny\Start Menu\Programs\XBMC\xbmc.lnk" opens up XBMC. The same is true for the Run box Win+R "path and filename.lnk", Enter

3
  • 3
    privvies? What does that mean? I searched Google on that word and the results were not related.
    – Hack-R
    Jan 24, 2018 at 16:24
  • 1
    @Hack-R sorry for my slang using privvies for meaning privelges or security permissions to execute Jan 24, 2018 at 18:19
  • 1
    @SunnyskyguyEE75 what if the .lnk file contains a shortcut to a terminal-based application (e.g. cmd.exe) and I want to remain within the same window. Is that possible?
    – stav
    Jul 31, 2019 at 8:19
25

START "" filename.lnk should do the trick

As long as there is no exe with the same name as the shortcut, you can omit the .lnk, so just START "" filename

2
  • as long as the .lnk file is in the path environment for windows it will work. otherwise not. YOu can run any service using win+R ...net start msiserver .. for example starts the Windows Installer service.. or any MS Console using run... xxx.msc (these are located in windows32 folder and in PATH) Jun 28, 2012 at 4:33
  • 6
    Actually, in order to work I had to do START "Name of the new window" "filename.lnk". With only one arg START was just creating a new command line window named after the first parameter. See related on StackOverflow: stackoverflow.com/questions/6139365/… Sep 19, 2013 at 15:44
3

These answers all fail to solve the issue. I indeed have the solution.

There is a simple answer to this question.

Use the PATHEXT variable and add .LNK to the list. Add .URL if you like.

Forever after, LNK files will execute JUST LIKE any other EXE. You don't even need to include .LNK when invoking them.

If you want the path to be correct when you launch one, remove the "target path" string from the shortcut properties and you will be able to pass relative paths to the LNK. As in "notepad++ somefile.txt" when you are in the directory.

If you put a folder in the path after doing this, you can simply drop shortcuts in there for a simple way to execute things without crowding your path with junk. Adding a path for every tom, d**k, or harry will indeed slow down your system and this will not. How much slow down? I don't know but nothing comes for free.

2
  • Nice and simple! Jun 11, 2023 at 19:46
  • Brilliant! Trust Windoze not to have made .lnk executable BY DEFAULT. Thanks for nothing, MS-DOS. Now I can put hundreds of shortcuts in C:\Windows\System32 (always on the PATH). Jul 9, 2023 at 17:31
2

The above solutions didn't work for me in 2017, so I experimented a bit.

It turns out that Windows (10 atleast) does make a distinction between shortcuts that link to a local path and shortcuts that are an url. What I found was that

  • local paths use the suffix .lnk
  • url-like paths have the suffix .url

So a shortcut to https://superuser.com/ would have the suffix .url while a shortcut to C:\Windows or to special locations like Control Panel would have the suffix .lnk.

If you want to execute the shortcut simply type shortcut.suffix in the cmd prompt where .suffix is the suffix according to the rule above. You must first cd to the folder containing your shortcut or enter the full path to the file. In your case

%userprofile%\Desktop\shortcut.suffix

entered into either the run dialog box (invoked via Win + R) or the cmd prompt would do the trick.

Windows and it's inconveniences.

1

First, find the location of the shortcut from which you start a cmd.exe shell. Right-click on the shortcut and choose "Properties". Look on the "General" tab and copy the "Location:" value.

Use the shortcut to start a reset window.

START "" "C:\Users\lit\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\cmd.exe.lnk" /K CD /D "%CD%" & EXIT
1

If you're trying to open a shortcut file with a command inside the registry, the above answers won't work.

The solution is simple though - add the /c flag:

cmd.exe /c C:\PathToShortcut\AdultContent.lnk
2
  • 2
    Is.... is anyone going to comment on the name of the link? :) Aug 9, 2023 at 2:44
  • Add start so the cmd window doesn't remain on screen: cmd.exe /c start C:\PathToShortcut\Something.lnk. There will still be a brief cmd window flash using this technique. Another option is: explorer.exe C:\PathToShortcut\Something.lnk. But note that the explorer option does not work if you also need to pass a path using %1 or %v and it uses more memory.
    – LesFerch
    Feb 3 at 0:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .