├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── README.md ├── index.js ├── license └── package.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [package.json] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "extends": "standard", 3 | "installedESLint": true, 4 | "plugins": [ 5 | "standard", 6 | "promise" 7 | ], 8 | "rules": { 9 | semi: ["error", "always"] 10 | } 11 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-shutdown-windows 2 | 3 | > Shutdown / Reboot your machine running Windows from within Node.JS 4 | 5 | ## Install 6 | 7 | ``` 8 | $ npm install --save node-shutdown-windows 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | const shutDownWin = require('node-shutdown-windows'); 15 | 16 | shutDownWin.logoff(); 17 | //=> logs the current user off 18 | 19 | shutDownWin.shutdown(); 20 | //=> shuts down the whole machine instantly 21 | 22 | shutDownWin.shutdown(20); 23 | //=> shuts down the whole machine in 20 seconds 24 | 25 | shutDownWin.shutdown(20, true); 26 | //=> shuts down the whole machine in 20 seconds, forceably killing all running applications 27 | 28 | shutDownWin.shutdown(20, false, 'The system will shut down in 20 seconds'); 29 | //=> shuts down the whole machine in 20 seconds, displaying a message until that time 30 | 31 | shutDownWin.reboot(); 32 | //=> reboots the whole machine instantly 33 | 34 | shutDownWin.reboot(20); 35 | //=> reboots the whole machine in 20 seconds 36 | 37 | shutDownWin.reboot(20, true); 38 | //=> reboots the whole machine in 20 seconds, forceably killing all running applications 39 | 40 | shutDownWin.reboot(20, false, 'The system will reboot in 20 seconds'); 41 | //=> reboots the whole machine in 20 seconds, displaying a message until that time 42 | 43 | shutDownWin.abort(); 44 | //=> aborts a startup / shutdown procedure 45 | ``` 46 | 47 | ## Documentation 48 | 49 | Please also take a look at https://technet.microsoft.com/de-de/library/bb491003.aspx, since this module is just a wrapper around the Windows `shutdown` command. 50 | 51 | ### logoff([timeout, force, message]) 52 | 53 | Logs off the current user. 54 | 55 | * `timeout` {Number} Sets the timer for system logoff in seconds 56 | * `force` {Boolean} Forces running applications to close 57 | * `message` {String} message Specifies a message to be displayed in the Message area of the System Shutdown window. You can use a maximum of 127 characters 58 | 59 | ### shutdown([timeout, force, message]) 60 | 61 | Shuts down the local computer. 62 | 63 | * `timeout` {Number} Sets the timer for system shutdown in seconds 64 | * `force` {Boolean} Forces running applications to close 65 | * `message` {String} message Specifies a message to be displayed in the Message area of the System Shutdown window. You can use a maximum of 127 characters 66 | 67 | ### reboot([timeout, force, message]) 68 | 69 | Reboots after shutdown. 70 | 71 | * `timeout` {Number} Sets the timer for system shutdown in seconds 72 | * `force` {Boolean} Forces running applications to close 73 | * `message` {String} message Specifies a message to be displayed in the Message area of the System Shutdown window. You can use a maximum of 127 characters 74 | 75 | ### abort() 76 | 77 | Aborts shutdown / logoff / reboot. 78 | 79 | ## License 80 | 81 | ISC © [Benedikt Reiser](http://benedikt-reiser.de) 82 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // see https://technet.microsoft.com/de-de/library/bb491003.aspx for details 4 | // right now, only local shutdown / reboot / logoff is implemented. 5 | // we need the ability to spawn processes 6 | const spawn = require('child_process').spawn; 7 | // shutdown command to be executed 8 | const shutdownCmd = 'shutdown'; 9 | 10 | /** 11 | * Logs off the current user 12 | * 13 | * @param {Number} timeout Sets the timer for system logoff in seconds 14 | * @param {Boolean} force Forces running applications to close 15 | * @param {String} message Specifies a message to be displayed in the Message area of the System Shutdown window. You can use a maximum of 127 characters 16 | * @returns {ChildProcess} 17 | */ 18 | exports.logoff = function (timeout, force, message) { 19 | // check if force flag is provided 20 | force = !!force; 21 | // build argumnets 22 | let args = ['-l']; 23 | if (timeout) { 24 | args.push('-t'); 25 | args.push(parseInt(timeout, 10)); 26 | } 27 | if (force) { 28 | args.push('-f'); 29 | } 30 | if (message) { 31 | args.push('-m'); 32 | args.push(`"${message}"`); 33 | } 34 | // execute the shutdown command 35 | return spawn(shutdownCmd, args); 36 | }; 37 | 38 | /** 39 | * Shuts down the local computer 40 | * 41 | * @param {Number} timeout Sets the timer for system shutdown in seconds 42 | * @param {Boolean} force Forces running applications to close 43 | * @param {String} message Specifies a message to be displayed in the Message area of the System Shutdown window. You can use a maximum of 127 characters 44 | * @returns {ChildProcess} 45 | */ 46 | exports.shutdown = function (timeout, force, message) { 47 | // check if force flag is provided 48 | force = !!force; 49 | // build argumnets 50 | let args = ['-s']; 51 | if (timeout) { 52 | args.push('-t'); 53 | args.push(parseInt(timeout, 10)); 54 | } 55 | if (force) { 56 | args.push('-f'); 57 | } 58 | if (message) { 59 | args.push('-m'); 60 | args.push(`"${message}"`); 61 | } 62 | // execute the shutdown command 63 | return spawn(shutdownCmd, args); 64 | }; 65 | 66 | /** 67 | * Reboots after shutdown 68 | * 69 | * @param {Number} timeout Sets the timer for system shutdown in seconds 70 | * @param {Boolean} force Forces running applications to close 71 | * @param {String} message Specifies a message to be displayed in the Message area of the System Shutdown window. You can use a maximum of 127 characters 72 | * @returns {ChildProcess} 73 | */ 74 | exports.reboot = function (timeout, force, message) { 75 | // check if force flag is provided 76 | force = !!force; 77 | // build argumnets 78 | let args = ['-r']; 79 | if (timeout) { 80 | args.push('-t'); 81 | args.push(parseInt(timeout, 10)); 82 | } 83 | if (force) { 84 | args.push('-f'); 85 | } 86 | if (message) { 87 | args.push('-m'); 88 | args.push(`"${message}"`); 89 | } 90 | // execute the shutdown command 91 | return spawn(shutdownCmd, args); 92 | }; 93 | 94 | /** 95 | * Aborts shutdown 96 | * 97 | * @returns {ChildProcess} 98 | */ 99 | exports.abort = function () { 100 | return spawn(shutdownCmd, ['-a']); 101 | }; 102 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2016, Benedikt Reiser 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-shutdown-windows", 3 | "version": "1.0.0", 4 | "description": "Shutdown and reboot your Windows from node", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/burnedikt/node-shutdown-windows.git" 12 | }, 13 | "keywords": [ 14 | "npm", 15 | "node", 16 | "shutdown", 17 | "windows", 18 | "reboot" 19 | ], 20 | "os" : [ "win32" ], 21 | "author": "Benedikt Reiser ", 22 | "license": "ISC", 23 | "bugs": { 24 | "url": "https://github.com/burnedikt/node-shutdown-windows/issues" 25 | }, 26 | "homepage": "https://github.com/burnedikt/node-shutdown-windows#readme", 27 | "devDependencies": { 28 | "eslint": "^3.1.1", 29 | "eslint-config-standard": "^5.3.5", 30 | "eslint-plugin-promise": "^2.0.0", 31 | "eslint-plugin-standard": "^2.0.0" 32 | } 33 | } 34 | --------------------------------------------------------------------------------