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?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
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.
"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
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
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
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
entered into either the run dialog box (invoked via
Win + R) or the cmd prompt would do the trick.
Windows and it's inconveniences.
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.
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