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

windows-shortcuts-gbk

v0.1.6

Published

Create, edit, and query Windows shortcuts (.lnk files) with GBK support

Downloads

10

Readme

windows-shortcuts

Create, edit, and query Windows shortcuts (.lnk files)

A Node.js API for shortcut.exe by Optimum X.

Note that this will not work for Electron apps - the shell.writeShortcutLink or shell.readShortcutLink function should be used instead.

Simple Usage Example

Creating a shortcut to notepad.exe in the current user's Start Menu:

var ws = require('windows-shortcuts');

ws.create("%APPDATA%/Microsoft/Windows/Start Menu/Programs/Notepad.lnk", "%WINDIR%/notepad.exe");

API

ws.create(path, [options], [callback])

ws.create(path, target, [callback])

Creates a new shortcut.

  • path - The file path to the new shortcut. This can be a folder, in which case a .lnk file will be created in that folder with the name of the target file, or the name of a .lnk file, which will be created. Note that a folder that does not exist will not be created. Environment variables like %WINDIR% can be used, but they will be expanded when the shortcut is created. If you want them to be expanded when the shortcut is clicked, use carets before the percent signs: ^%WINDIR^%.
  • options - An object with the following optional parameters:
    • target - The file path to the shortcut's target. See above about environment variables.
    • args - The arguments to be passed to the shortcut, as a string.
    • workingDir - The working directory of the shortcut.
    • runStyle - State to open the window in: ws.NORMAL (1), ws.MAX (3), or ws.MIN (7).
    • icon - The path to the shortcut icon file.
    • iconIndex - An optional index for the image in the icon file.
    • hotkey - A number representing a hotkey. To find out this value, create a shortcut manually and use ws.query on it. Sorry about that inconvenience, but there isn't any more documentation either with shortcut.exe or from Microsoft.
    • desc - A string description of the shortcut.
  • target - If a string is passed as the second parameter, it is used as the options.target value (see above).
  • callback - A function to be executed when ws.create is finished executing. One argument is passed to it: null if there was no error, or a string error message if there was.

Example:

var ws = require('windows-shortcuts');

ws.create("foo.lnk", {
	target : "%APPDATA%/Bar/foo.js",
	args : '2 "baz quux"',
	runStyle : ws.MIN,
	desc : "Does cool stuff."
}, function(err) {
	if (err)
		throw Error(err);
	else
		console.log("Shortcut created!");
});

ws.edit(path, options, [callback])

Edits an existing shortcut, applying new options. Parameters are the same as above.

Example:

ws.edit("foo.lnk", {runStyle : ws.MAX});

ws.query(path, callback)

Collects information about an existing shortcut. The callback is called with two parameters:

  • error - A string error message if there was an error, otherwise null
  • options - The options set on the shortcut with the same properties as above, except an additional property expanded is added which contains the file name properties with any environment variables expanded. For example, if options.target is "%WINDIR%/foo.exe", options.expanded.target would be "C:/Windows/foo.exe".

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

Testing

npm test

Compatibility

Only tested on Windows 7, but shortcut.exe says is compatible with Windows 95 or later, so it should work on modern versions of Windows.


Licensed under the MIT License.