Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

elevator

resin-io-modules156MIT2.2.3

Windows UAC elevation that just works

windows, win32, uac, elevate, elevator

readme

elevator

Windows UAC elevation that just works.

npm version dependencies Build status ![Gitter](https://badges.gitter.im/Join Chat.svg)

Description

This module is a thin wrapper around the awesome elevate.exe utility by kliu, which is a small C open source application with x64 and ia32 support that just works.

This module doesn't make use of NodeJS C/C++ bindings and instead relies on executing the .exe file direcly in a way that is electron friendly even when the application is packaged in an asar archive.

Of course, this means that this NodeJS module is subjected to the Windows versions and architectures such supports. Windows Vista (or newer) is required.

Installation

Install elevator by running:

$ npm install --save elevator

Documentation

elevator.execute(command, [options], callback)

This function will yield an Error containing a code that equals ELEVATE_CANCELLED if the elevation was cancelled by the user.

Kind: static method of elevator
Summary: Execute a command with UAC elevation
Access: public

Param Type Default Description
command Array.<String> | command
[options] Object {} options
[options.terminating] Boolean | Launches a terminating command processor; equivalent to "cmd /c command".
[options.persistent] Boolean | Launches a persistent command processor; equivalent to "cmd /k command".
[options.doNotPushdCurrentDirectory] Boolean | When using -c or -k, do not pushd the current directory before execution.
[options.unicode] Boolean | When using -c or -k, use Unicode; equivalent to "cmd /u".
[options.hidden] Boolean | When using -c or -k, start "cmd" in hidden mode.
[options.waitForTermination] Boolean | Waits for termination; equivalent to "start /wait command".
callback function | callback (error, stdout, stderr)

Example

elevator.execute([ 'cmd.exe' ], {
  waitForTermination: true
}, function(error, stdout, stderr) {
  if (error) {
    throw error;
  }

  console.log(stdout);
  console.log(stderr);
});

elevator.executeSync(command, [options]) ⇒ String

This function will throw an Error containing a code that equals ELEVATE_CANCELLED if the elevation was cancelled by the user.

Kind: static method of elevator
Summary: Execute a command with UAC elevation (Sync)
Returns: String - stdout buffer
Access: public

Param Type Default Description
command Array.<String> | command
[options] Object {} options
[options.terminating] Boolean | Launches a terminating command processor; equivalent to "cmd /c command".
[options.persistent] Boolean | Launches a persistent command processor; equivalent to "cmd /k command".
[options.doNotPushdCurrentDirectory] Boolean | When using -c or -k, do not pushd the current directory before execution.
[options.unicode] Boolean | When using -c or -k, use Unicode; equivalent to "cmd /u".
[options.hidden] Boolean | When using -c or -k, start "cmd" in hidden mode.
[options.waitForTermination] Boolean | Waits for termination; equivalent to "start /wait command".

Example

elevator.executeSync([ 'cmd.exe' ], {
  waitForTermination: true
});

Support

If you're having any problem, please raise an issue on GitHub and the Resin.io team will be happy to help.

Tests

Run the test suite by doing:

$ gulp test

Contribute

Before submitting a PR, please make sure that you include tests, and that jshint runs without any warning:

$ gulp lint

License

The project is licensed under the MIT license.

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

v2.2.3 - 2017-04-20

Changed

  • Fix logical error when yielding back a cancellation error.

v2.2.2 - 2017-04-14

Changed

  • Log debug messages to stdout.

v2.2.1 - 2017-04-14

Changed

  • Add error code to error message.

v2.2.0 - 2017-04-13

Changed

  • Log debugging information using the debug module.

v2.1.0 - 2016-06-17

Added

  • Throw a distinguishable error if the user cancels elevation.

v2.0.0 - 2016-06-17

Added

  • Add hidden option.
  • Add doNotPushdCurrentDirectory option.

Removed

  • Remove pushdCurrentDirectory option.