访问 Node 上的 Windows 快捷方式 (.lnk) 数据

Raf*_*ael 6 windows node.js

有什么方法可以解析 Node 中 .lnk 文件的快捷方式数据(例如,主要是它指向的路径)?

Ale*_*lex 6

如果您使用Electron,它有一个内置方法:

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

import { shell } from 'electron';

const parsed = shell.readShortcutLink(shortcutPath);
Run Code Online (Sandbox Code Playgroud)
  • target 字符串- 要从此快捷方式启动的目标。
  • cwd 字符串(可选)- 工作目录。默认为空。
  • args 字符串(可选)- 从该快捷方式启动时应用于目标的参数。默认为空。
  • description 字符串(可选)- 快捷方式的描述。默认为空。
  • icon 字符串(可选)- 图标的路径,可以是 DLL 或 EXE。icon 和 iconIndex 必须一起设置。默认为空,即使用目标的图标。
  • iconIndex Number(可选)- 当图标是 DLL 或 EXE 时,图标的资源 ID。默认值为 0。
  • appUserModelId 字符串(可选)- 应用程序用户模型 ID。默认为空。


Ami*_*ein 2

您可以使用 npm 包windows-shortcuts

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

例子:

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.' }
*/
Run Code Online (Sandbox Code Playgroud)