6

Is there any way I can parse shortcut data from .lnk files in Node (for instance, and mainly, the path it's pointing at)?

3 Answers 3

6

If you're using Electron, it has a built-in method:

https://www.electronjs.org/docs/api/shell#shellreadshortcutlinkshortcutpath-windows

import { shell } from 'electron';

const parsed = shell.readShortcutLink(shortcutPath);
  • target String - The target to launch from this shortcut.
  • cwd String (optional) - The working directory. Default is empty.
  • args String (optional) - The arguments to be applied to target when launching from this shortcut. Default is empty.
  • description String (optional) - The description of the shortcut. Default is empty.
  • icon String (optional) - The path to the icon, can be a DLL or EXE. icon and iconIndex have to be set together. Default is empty, which uses the target's icon.
  • iconIndex Number (optional) - The resource ID of icon when icon is a DLL or EXE. Default is 0.
  • appUserModelId String (optional) - The Application User Model ID. Default is empty.
3

Aminadav Glickshtein's answer didn't work for me since the package involved has a problem in electron projects, as per my comment. The following package worked better:

https://github.com/felixrieseberg/windows-shortcuts-ps

1
  • I found this windows-shortcuts-ps to work very well, within Electron (9), where none of the above would. It exports a function and returns a Promise, so you use it actually this way: ``` const { getPath } = require('windows-shortcuts-ps') const truefilePath = await getPath(lnkFilePath) ``` Oct 8, 2020 at 23:21
2

You can use the npm package windows-shortcuts

https://www.npmjs.com/package/windows-shortcuts

Example:

ws.query("C:/ProgramData/Microsoft/Windows/Start Menu/Windows Update.lnk", 
console.log);

/* From console:
null { expanded:
   { args: 'startmenu',
     workingDir: 'C:\\Windows\\system32',
     icon: 'C:\\Windows\\system32\\wucltux.dll' },
  target: '%windir%\\system32\\wuapp.exe',
  args: 'startmenu',
  workingDir: '%windir%\\system32',
  runStyle: 1,
  icon: '%windir%\\system32\\wucltux.dll',
  iconIndex: '0',
  hotkey: 0,
  desc: 'Delivers software updates and drivers, and provides automatic updating options.' }
*/
2
  • Unfortunately this library doesn't work in electron projects and shows no signs of being fixed: github.com/j201/windows-shortcuts/issues/9 Jan 9, 2020 at 21:23
  • 1. not working with non-ascii chars 2. very slow because spawns separate process instead of reading lnks with fs module
    – VityaSchel
    May 5, 2022 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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