Skip to content

Electron subprocesses with administrative privileges, prompting the user with an OS dialog if necessary.

License

Notifications You must be signed in to change notification settings

david-mohr/electron-sudo

 
 

Repository files navigation

Electron subprocess with administrative privileges

Run a subprocess with administrative privileges, prompting the user with a graphical OS dialog if necessary. Useful for background subprocesse which run native Electron apps that need sudo.

Uses in-built OS features, no binaries required

Features

  • Supports spawn and exec subprocess behavior
  • Supports applications packaged as asar archive
  • Separate password prompt for each call (use sh or bat script for single prompt)
  • No external dependencies, does not depend on OS versions

Installation

npm install david-mohr/electron-sudo

Usage

Note: Your command should not start with the sudo prefix.

Version 5

import sudo from 'electron-sudo';

/* Spawn subprocess behavior */
let cp = await sudo.spawn(
  'echo', ['$PARAM'], {env: {PARAM: 'VALUE'}}
);
cp.on('close', () => {
  /*
    cp.output.stdout (Buffer)
    cp.output.stderr (Buffer)
  */
});

/* Exec subprocess behavior */
let result = await sudo.exec(
  'echo $PARAM', {env: {PARAM: 'VALUE'}}
);
/* result is an object with props stdout and stderr (both Buffers) */

Tests

npm i && npm test

Thanks

Based on the original electron-sudo by Aleksandr Komlev

About

Electron subprocesses with administrative privileges, prompting the user with an OS dialog if necessary.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%