read_path_from_lnk

Function read_path_from_lnk 

Source
pub fn read_path_from_lnk<P: AsRef<Path>>(
    lnk_path: P,
    encoding: Encoding,
) -> Result<PathBuf>
Expand description

Open and parse a shell link

All string which are stored in the lnk file are encoded with either Unicode (UTF-16LE) of any of the Windows code pages. Which of both is being used is specified by the [LinkFlags::IS_UNICODE] flag. Microsoft documents this as follows:

If this bit is set, the StringData section contains Unicode-encoded strings; otherwise, it contains strings that are encoded using the system default code page.

(https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-shllink/ae350202-3ba9-4790-9e9e-98935f4ee5af)

The system default code page is stored in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\ACP

Because we do not know what the system default code page was, you must specify this using the encoding parameter (see below). If you you do not know the system default code page either, you’re lost. There is no way to correctly guess the used code page from the data in the lnk file.

  • path - path of the lnk file to be analyzed
  • encoding - character encoding to be used if the lnk file is not Unicode encoded