npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

get-windows-shortcut-properties

v1.3.0

Published

Easy API to get the properties of a Windows .lnk shortcut with Node

Downloads

6,086

Readme

get-windows-shortcut-properties

A Node.js library to get the properties of a Windows .lnk or .url shortcut file.

This library is completely SYNCHRONOUS.

Install Instructions

  1. Install Node/npm
  2. npm install --save get-windows-shortcut-properties

Usage

Single File Example

const getWindowsShortcutProperties = require('get-windows-shortcut-properties');

if (process.platform === 'win32') {
  const output = getWindowsShortcutProperties.sync('../Sublime Text.lnk');

  if (output) {
    console.log(output);
  } else {
    console.log('There was an error');
  }
}

Multiple Files Example

const getWindowsShortcutProperties = require('get-windows-shortcut-properties');

if (process.platform === 'win32') {
  const output = getWindowsShortcutProperties.sync([
    '../Sublime Text.lnk',
    'C:\\Users\\Public\\Desktop\\Firefox.lnk'
  ]);
  if (output) {
    console.log(output);
  } else {
    console.log('There was an error');
  }
}

Custom Logger Single File Example

const getWindowsShortcutProperties = require('get-windows-shortcut-properties');

if (process.platform === 'win32') {
  const output = getWindowsShortcutProperties.sync('../Sublime Text.lnk', function (message, error) {
    console.log(message, error);
  });

  if (output) {
    console.log(output);
  } else {
    console.log('There was an error');
  }
}

Custom Logger Multiple Files Example

const getWindowsShortcutProperties = require('get-windows-shortcut-properties');

if (process.platform === 'win32') {
  const shortcuts = [
    '../Sublime Text.lnk',
    'C:\\Users\\Public\\Desktop\\Firefox.lnk'
  ];
  function customLogger (message, error) {
    console.log(message, error);
  }
  const output = getWindowsShortcutProperties.sync(shortcuts, customLogger);

  if (output) {
    console.log(output);
  } else {
    console.log('There was an error');
  }
}

Documentation

getWindowsShortcutProperties.sync API

  • First argument: filePath
    • TYPE: String or Array of Strings
    • DESCRIPTION: The path to the shortcut file you want the properties of, or an array of strings to multiple files
    • REQUIREMENTS: Strings must point to a file that exists and ends in .lnk or .url
    • PERFORMANCE: Passing in an array of files is significantly faster than running this library once for every file. Each run has a ~0.25s overhead cost of spinning up PowerShell. So we group all your files into one request and they run together. (meaning 100 individual runs = 25 seconds versus one run with 100 files passed in = 0.4s).
    • WARNING: Passing in too many files at once will produce a PowerShell command that is too long to run. For me it worked with 92 files and no more. But it's all about the total command length produced by this library. So longer file paths will mean fewer files can be passed in at once. Relative paths are normalized by Node, so using them will not help or hurt.
  • Second argument: customLogger
    • TYPE: function
    • DESCRIPTION: This is an optional function that is called with a message and error object (if something fails, or you pass in bad inputs). Defaults to using console.error if not passed in.

getWindowsShortcutProperties.sync Output

Returns undefined if all files errored, or an Array of Objects for each successful file:

[
  {
    FullName: 'C:\\Users\\Owner\\Desktop\\DaVinci Resolve.lnk',
    Arguments: '',
    Description: 'Video Editor',
    Hotkey: '',
    IconLocation: 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\ResolveIcon.exe,0',
    RelativePath: '',
    TargetPath: 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\Resolve.exe',
    WindowStyle: '1',
    WorkingDirectory: 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\'
  }
]

See Microsoft's Shortcut Documentation for information on these keys and their values.

If you pass in an array of files, and some succeed, you will get an array of the success and console errors for the other files (unless you pass in a customLogger function, in which case it gets called when errors occur).

getWindowsShortcutProperties.translate API

  • First argument: shortcutProperties
    • TYPE: Array of Objects
    • DESCRIPTION: Each object in the array is the properties for one shortcut, we convert this over to something more human readable.
  • Second argument: customLogger
    • TYPE: function
    • DESCRIPTION: This is an optional function that is called with a message and error object (if something fails, or you pass in bad inputs). Defaults to using console.error if not passed in.

getWindowsShortcutProperties.translate Output

Takes in the ouput of getWindowsShortcutProperties.sync, and then translates it into the Input for create-desktop-shortcuts (a different Node.js library).

const microsoftNamingConventions = [
  {
    FullName: 'C:\\Users\\Owner\\Desktop\\DaVinci Resolve.lnk',
    Arguments: '--foo',
    Description: 'Video Editor',
    Hotkey: 'Ctrl+F10',
    IconLocation: 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\ResolveIcon.exe,0',
    RelativePath: '',
    TargetPath: 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\Resolve.exe',
    WindowStyle: '1',
    WorkingDirectory: 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\'
  }
];
const output = getWindowsShortcutProperties.translate(microsoftNamingConventions); // produces the below output
const output = [
  {
    filePath: 'C:\\Users\\Owner\\Desktop\\DaVinci Resolve.lnk',
    arguments: '--foo',
    comment: 'Video Editor',
    hotkey: 'Ctrl+F10',
    icon: 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\ResolveIcon.exe,0',
    relativePath: '',
    targetPath: 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\Resolve.exe',
    windowMode: 'normal',
    workingDirectory: 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\'
  }
];

OS Support

Only works on Windows OS's that have PowerShell installed.


Credits

Author: The Jared Wilcurt

This repo was inspired by:

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

How can you help improve this repo?

  • Report bugs in the GitHub issues
  • Request features
  • Fix reported bugs with a PR
  • Offer an async and sync mode, instead of just sync.
  • This repo is written using require for imports. It would be nice to also support ESM imports.

Related Libraries: