How do I "persuade" programs open an actual .lnk file in Windows 7?
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?
Solution 1:
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:
-
HxD
Open dialog Yes
Drag-and-drop No -
XVI32, Free Hex Editor Neo, Tiny Hexer, wxHexEditor, Hex-Editor MX, Frhed
Open dialog No
Drag-and-drop Yes
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
- [MS-SHLLINK]: Shell Link (.LNK) Binary File Format
- LNK - Forensics Wiki
Solution 2:
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 theEXE
file pointed to by theLNK
file.
Opening LNK
files in HxD hex editor:
- Open them as you would any file using the Open dialog (
File
→Open
)
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"
Solution 3:
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:
- lnk-parser
- LnkEditorGUI
- lnkedit
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!