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

Node.js 访问节点上的Windows快捷方式(.lnk)数据,node.js,windows,Node.js,Windows,是否有任何方法可以解析节点中.lnk文件的快捷方式数据(例如,主要是它所指向的路径)?您可以使用npm包windows快捷方式 例如: ws.query("C:/ProgramData/Microsoft/Windows/Start Menu/Windows Update.lnk", console.log); /* From console: null { expanded: { args: 'startmenu', workingDir: 'C:\\Windows\\s

是否有任何方法可以解析节点中.lnk文件的快捷方式数据(例如,主要是它所指向的路径)?

您可以使用npm包
windows快捷方式

例如:

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.' }
*/

根据我的评论,Aminadav Glickshtein的回答不适用于我,因为所涉及的包在电子项目中存在问题。以下方案效果更好:

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

  • target
    String-要从此快捷方式启动的目标
  • cwd
    String(可选)-工作目录。默认值为空
  • args
    String(可选)-从此快捷方式启动时应用于目标的参数。默认值为空
  • description
    String(可选)-快捷方式的说明。默认值为空
  • 图标
    字符串(可选)-图标的路径可以是DLL或EXE。图标和图标索引必须一起设置。默认值为空,使用目标图标
  • iconIndex
    Number(可选)-图标为DLL或EXE时图标的资源ID。默认值为0
  • appUserModelId
    String(可选)-应用程序用户模型ID。默认值为空

不幸的是,该库在electron项目中不起作用,也没有被修复的迹象:我发现该库在electron(9)中工作得非常好,而上面的任何一个都不会。它导出一个函数并返回一个承诺,因此您实际上是这样使用它的:```const{getPath}=require('windows-shortcuts-ps')const truefilePath=await getPath(lnkFilePath)```
import { shell } from 'electron';

const parsed = shell.readShortcutLink(shortcutPath);