nodejs控制windows关机重启

tech2022-08-12  157

废话少说,上代码

关机

const { exec } = require('child_process'); function shutdownWindow() { let command = exec('shutdown -s -t 00', function(err, stdout, stderr) { if(err || stderr) { console.log("shutdown failed" + err + stderr); } }); command.stdin.end(); command.on('close', function(code) { console.log("shutdown", code); }); }

重启

const { exec } = require('child_process'); function rebootWindow() { let command = exec('reboot', function(err, stdout, stderr) { if(err || stderr) { console.log("reboot failed" + err + stderr); } }); command.stdin.end(); command.on('close', function(code) { console.log("reboot", code); }); }
最新回复(0)