Windows – Modifying Windows Shortcut .lnk-file’s target into a relative path

shortcutswindows

Copied from here, as it's locked over there; I hope it belongs here.

Is it possible to open .lnk (windows shortcut) in a hex editor, and change the absolute shortcut path into a relative one? Can we do this in Windows? The edit command in cmd can open link files but it's difficult to read and edit. Is there any hex editor in windows that can open an .lnk file and allow me to edit it? Do I need to take it to Linux or does Linux recognize .lnk as a shortcut too?

I want to do this not only for running .exe files, but also for pointing to folders (that is, shortcut to folders). A batch file which executes explorer.exe with the target folder as parameter can do this actually, but I want to know if there is any way to actually edit the data in the .lnk file itself

Best Answer

Is there any hex editor in windows that can open lnk file and allow me to edit it?

I don't see why this should be a problem for any hex editor. It might edit the source if you create a symlink or something, but unless the editor specifically has a feature to transparently resolve shortcuts and edit the source, it should work just fine for editing the .LNK itself. I just tried editing both file and dir shortcuts using HxD and had no issues. Of course, if you're looking for a hex editor that actually parses the file and allows you to modify it, you might be out of luck.

There are also command-line programs that you can use to create and modify various aspects of shortcuts, as also Visual Basic scripts.

However, all this is pointless because Windows does not support relative shortcuts in the first place, as can be seen from this Raymond Chen post (be sure to read the associated comments as well).