Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

A .lnk file in Windows is an actual file intended to be a shortcut to another file. However, I really do want to view the contents on the .lnk file itself. I'm finding it literally impossible to do so; no matter what I try, my applications are opening the contents of the file it points to (drag/drop into text or hex editor, file | open from text or hex editor, etc.)

Is there some way I can tell a program to actually open the .lnk file instead of the file it points to?

share|improve this question
3  
You can always rename it to .txt or something. Usually this doesn't cause it to lose any data. –  Chipperyman Jun 9 at 23:31
1  
@Chipperyman Except that that doesn't work. You cannot easily rename .lnk files with a new extension. –  fredsbend Jun 11 at 6:13

7 Answers 7

up vote 16 down vote accepted

Opening shortcuts

In order to edit a shortcut you obviously need to open it first, and that proves to be tricky. In some cases you can force programs into loading shortcut files by using a command-line argument:

"X:\Path\to\program.exe" "X:\my shortcut.lnk"

Whether the link target or the actual shortcut file is loaded depends on the program, though. Here's a list (in no particular order) of some free hex editors which supports them out of the box:


Workaround

In case you're unable to load the content of a shortcut file, you can open a command prompt and rename the .lnk file to a different, non-existent extension such as .lne:

cd /d "X:\Folder\containing\shortcuts"
ren "my shortcut.lnk" "my shortcut.lne"

If you have multiple files you can also rename all of them at once:

ren *.lnk *.lne

You will be then able to treat those shortcuts just like regular files. When you're done, make sure to rename them back to restore their usual functionality.


Additional information

A shortcut, or shell link, contains metadata information used to access a specific link target. It's parsed and interpreted by the Windows shell. From the official documentation:

The shell link structure stores various information that is useful to end users, including:

  • A keyboard shortcut that can be used to launch an application.

  • A descriptive comment.

  • Settings that control application behavior.

  • Optional data stored in extra data sections.

Source: [MS-SHLLINK]: Shell Link (.LNK) Binary File Format - Overview

Shortcuts are stored as binary files, and can't be edited using a standard text editor. A typical .lnk file looks something like this internally:

00000000  4C 00 00 00 01 14 02 00 00 00 00 00 C0 00 00 00  L...........À...
00000010  00 00 00 46 DC 03 00 02 20 00 00 00 C6 EF 52 BE  ...FÜ... ...ÆïR¾
00000020  10 04 CA 01 C6 EF 52 BE 10 04 CA 01 60 45 8A 67  ..Ê.ÆïR¾..Ê.`EŠg
00000030  20 04 CA 01 00 9A 04 00 00 00 00 00 01 00 00 00   .Ê..š..........

The first twenty bytes are always the following ones:

4C 00 00 00 01 14 02 00 00 00 00 00 C0 00 00 00 00 00 00 46

Further reading

share|improve this answer
    
Using HxD to open it via File | Open actually seems to have opened the .lnk file. Thanks. –  Jez Jun 10 at 13:24
    
@Jez I've updated my post to include some extra information. Let me know if you have any further questions. –  and31415 Jun 11 at 23:08

I've tried this and it works for me on Windows 8.1:

Opening LNK files in Notepad:

  • Just drag and drop them into the Notepad window. If you open them from the Open dialog, Notepad will open the EXE file pointed to by the LNK file.

Opening LNK files in HxD hex editor:

  • Open them as you would any file using the Open dialog (FileOpen)

Opening LNK files using the command prompt:

  • Navigate to the folder containing the LNK files and type the command: TYPE SHORTCUTNAME.LNK

Opening LNK files in just about any program:

  • Start the command prompt, navigate to the folder where the program is located, use the command: PROGRAM_NAME.EXE "path to LNK file"
share|improve this answer

The whole point of a .lnk file is for Windows to treat it as a link to another file so it should be hard to edit!

Perhaps it would help if you described WHY you want to edit it. You can change the settings of a .lnk file by right-clicking and choosing Properties.

If you really want to edit it, you need a special tool. There are a few of these including:

NB: I've not tried any of these, just Googled them.

UPDATE:

Don't know why I didn't think of this before but you can edit the properties via PowerShell. From this previous answer on Stack Overflow:

Copy-Item $sourcepath $destination  ## Get the lnk we want to use as a template
$shell = New-Object -COM WScript.Shell
$shortcut = $shell.CreateShortcut($destination)  ## Open the lnk
$shortcut.TargetPath = "C:\path\to\new\exe.exe"  ## Make changes
$shortcut.Description = "Our new link"  ## This is the "Comment" field
$shortcut.Save()  ## Save

As this uses the Shell COM object, you could also do this with WSH or even VBA in Office!

share|improve this answer
2  
I want to edit its contents, preferably in a hex editor, because I think it might be corrupt and I don't trust Explorer to properly tell me its contents. –  Jez Jun 9 at 20:32
    
I suppose that recreating it is out then? If so, try one of the editors though I'm not sure what would have corrupted it. –  Julian Knight Jun 9 at 20:34
1  
Well, it has never been hard to edit, at least in Windows XP. It was in fact harder to convince a program to treat it similarly to a symlink. Running any console app, e.g. edit, with the argument of path to shortcut will open the shortcut file. The programs who treat the shortcut similarly to a symlink do parse it themselves (maybe via shell functions). Has Windows resorted to using symlinks looking like shortcuts after XP? –  Ruslan Jun 10 at 10:02
    
The price of progress! Not much point in having a mechanism to define links that most apps then ignore. I don't know of many reasons to need to edit .lnk's directly. –  Julian Knight Jun 10 at 12:56
3  
@JulianKnight I had a use once for generating them programmatically for placement in a folder that acted as an index. I had to assume no rights to install software, but we were already using VBA. Modifying a template .lnk proved easier than generating one from scratch. –  Chris H Jun 10 at 15:05

.LNK files are interpreted by the shell. If you open up a command prompt and invoke your editing tool (let's just say Notepad for example) using the .LNK file as an argument, that should bypass the shell and open up the contents of the .LNK file itself.

notepad.exe shortcut.lnk
share|improve this answer
    
Nope, that doesn't work. It opens up the file the .lnk points to. –  Jez Jun 9 at 21:23
    
What application are you trying to open the link up in? –  Wes Sayeed Jun 9 at 21:41
3  
That is incorrect. I've tried this answer and it does work. –  Vinayak Jun 9 at 22:40
3  
@Vinayak That's a pretty bold statement. It may work for you in the situation you are using it in but it might not work for Jez. –  Chipperyman Jun 10 at 2:15

If you use CMD to run a program with the link file as a parameter, that parameter is passed verbatim to the program. It is up to the program to decide how to handle the link.

I have tested this with FRHED, the freeware (and portable) hex editor: when you run it from the command line, passing a link as parameter, it prompts you whether you want to open the file linked to (Yes), the link itself (No), or Cancel.

Oddly, if you use Open within the FRHED File menu, it opens the target file without asking.

On XP I have FRHED in my SendTo context menu, and that works the same way as CMD. I imagine Win7 is similar (I use a Win7 system for a dedicated application, and I will do simple tests on it, as above, but I don't mess with its configuration).

share|improve this answer
1  
That isn't Windows prompting you. That's Frhed asking you what to do –  Vinayak Jun 9 at 22:52
    
Quite right: silly of me - I'll change my answer. –  AFH Jun 9 at 23:06
    
I find putting Notepad into my SendTo menu to be very useful, letting me open any file (including shortcuts) in Notepad. –  Scott Jun 10 at 20:35
    
Final (?) observation: any DOS-based view or edit program will always open the link, never the target, since the DOS file open function does not know anything about links, so makes no special handling for them, unlike the Windows file open. –  AFH Jun 10 at 21:19

.lnk files are just files until a higher-level component such as Explorer.EXE assigns a maning to them. At a lower (NTFS) level, they still have a normal structure including data stream. In particular, the whole content is in the foo.lnk::$DATA stream. Not all higher-level tools will recognize that syntax. If they just assume it's a weird filename and pass it on, they will get the .lnk contents.

E.g. on the command line MORE < foo.lnk::$DATA > con would print the data, but it's a bit gibberish (parts are binary)

share|improve this answer

If you have reason to edit such files often, add a shortcut to notepad.exe to your SendTo folder (In Win 7: C:\Users\USER\AppData\Roaming\Microsoft\Windows\SendTo). This makes "Send to notepad.exe" available from your Rt. Click context menu. The .ink file will open, and can be edited, and saved in notepad.exe.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.