{"id":13798375,"url":"https://github.com/automation-stack/electron-sudo","last_synced_at":"2025-04-04T14:04:19.579Z","repository":{"id":53856911,"uuid":"46807602","full_name":"automation-stack/electron-sudo","owner":"automation-stack","description":"Electron subprocesses with administrative privileges, prompting the user with an OS dialog if necessary.","archived":false,"fork":false,"pushed_at":"2019-02-26T10:16:56.000Z","size":2585,"stargazers_count":384,"open_issues_count":20,"forks_count":55,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-28T13:06:47.696Z","etag":null,"topics":["electron","elevate","privileges","prompt","sudo","uac"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/automation-stack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-24T17:31:34.000Z","updated_at":"2025-03-25T16:04:49.000Z","dependencies_parsed_at":"2022-08-23T08:30:46.975Z","dependency_job_id":null,"html_url":"https://github.com/automation-stack/electron-sudo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/automation-stack%2Felectron-sudo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/automation-stack%2Felectron-sudo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/automation-stack%2Felectron-sudo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/automation-stack%2Felectron-sudo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/automation-stack","download_url":"https://codeload.github.com/automation-stack/electron-sudo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190224,"owners_count":20898699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["electron","elevate","privileges","prompt","sudo","uac"],"created_at":"2024-08-04T00:00:42.731Z","updated_at":"2025-04-04T14:04:19.545Z","avatar_url":"https://github.com/automation-stack.png","language":"JavaScript","readme":"## Electron subprocess with administrative privileges\n\nRun 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.\n\n- `Windows`, uses [elevate utility](https://github.com/automation-stack/electron-sudo/tree/master/src/vendor/win32) with native `User Account Control (UAC)` prompt (no `PowerShell` required)\n- `OS X`, uses bundled [applet](https://github.com/automation-stack/electron-sudo/tree/master/src/bin/applet.app) (inspired by  [Joran Dirk Greef](https://github.com/jorangreef))\n- `Linux`, uses system `pkexec` or [gksudo](http://www.nongnu.org/gksu) (system or bundled).\n\nIf you don't trust binaries bundled in `npm` package you can manually build tools and use them instead.\n\n\u003cimg height=\"150px\" src=\"./assets/win32.png\"\u003e \u003cimg height=\"150px\" src=\"./assets/osx.png\"\u003e \u003cimg height=\"150px\" src=\"./assets/linux.png\"\u003e\n\n## Features\n  - Supports ```spawn``` and ```exec``` subprocess behavior\n  - Supports applications packaged as ```asar``` archive\n  - Separate password prompt for each call (use ```sh``` or ```bat``` script for single prompt)\n  - No external dependencies, does not depend on OS versions\n\n## Installation\n```\nnpm install electron-sudo\n```\n\n## Usage\n**Note: Your command should not start with the ```sudo``` prefix.**\n\n### Version 4.0.*\n\n```js\nimport Sudoer from 'electron-sudo';\n\nlet options = {name: 'electron sudo application'},\n    sudoer = new Sudoer(options);\n\n/* Spawn subprocess behavior */\nlet cp = await sudoer.spawn(\n  'echo', ['$PARAM'], {env: {PARAM: 'VALUE'}}\n);\ncp.on('close', () =\u003e {\n  /*\n    cp.output.stdout (Buffer)\n    cp.output.stderr (Buffer)\n  */\n});\n\n/* Exec subprocess behavior */\nlet result = await sudoer.exec(\n  'echo $PARAM', {env: {PARAM: 'VALUE'}}\n);\n/* result is Buffer with mixed (both stdout and stderr) output */\n\n\n/* Usage with Vanila JS */\n\nvar Sudoer = require('electron-sudo').default;\nvar sudoer = new Sudoer(options);\nsudoer.spawn('echo', ['$PARAM'], {env: {PARAM: 'VALUE'}}).then(function (cp) {\n  /*\n    cp.output.stdout (Buffer)\n    cp.output.stderr (Buffer)\n  */\n});\n\n```\n\n### Version 3.0.* (deprecated)\n\n```js\nvar sudo = require('electron-sudo');\nvar options = {\n  name: 'Your application name',\n  icns: '/path/to/icns/file' // (optional, only for MacOS),\n  process: {\n    options: {\n      // Can use custom environment variables for your privileged subprocess\n      env: {'VAR': 'VALUE'}\n      // ... and all other subprocess options described here\n      // https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback\n    },\n    on: function(ps) {\n      ps.stdout.on('data', function(data) {});\n      setTimeout(function() {\n        ps.kill()\n      }.bind(ps), 50000);\n    }\n  }\n};\nsudo.exec('echo hello', options, function(error) {});\n```\n\n## Tests\n```\nnpm i \u0026\u0026 npm test\n```\n\n## Usage with Webpack\n\nWebpack config should contain ```__dirname``` equals ```true``` for work properly\n\n```js\n\nlet nodeModules = fs.readdirSync('./node_modules')\n    .filter((module) =\u003e {\n        return module !== '.bin';\n    })\n    .reduce((prev, module) =\u003e {\n        return Object.assign(prev, {[module]: 'commonjs ' + module});\n    }, {});\n\nexport default {\n    ...\n    target: 'electron',\n    node: {\n        /* http://webpack.github.io/docs/configuration.html#node */\n        __dirname: true\n    },\n    externals: nodeModules\n};\n```\n","funding_links":[],"categories":["Library","Tools"],"sub_categories":["Uncategorized","For Electron"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautomation-stack%2Felectron-sudo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautomation-stack%2Felectron-sudo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautomation-stack%2Felectron-sudo/lists"}