【问题标题】:Access Windows shortcuts (.lnk) data on Node访问 Node 上的 Windows 快捷方式 (.lnk) 数据
【发布时间】:2018-02-04 16:41:37
【问题描述】:

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

【问题讨论】:

    标签: node.js windows


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 我发现这个 windows-shortcuts-ps 在 Electron (9) 中工作得非常好,而以上都不是。它导出一个函数并返回一个 Promise,所以你实际上是这样使用它的:``` const { getPath } = require('windows-shortcuts-ps') const truefilePath = await getPath(lnkFilePath) ```
      【解决方案3】:

      可以使用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.' }
      */
      

      【讨论】:

      猜你喜欢
      • 2012-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-23
      • 2021-09-27
      • 2018-07-17
      • 2013-11-08
      相关资源
      最近更新 更多