废话少说,上代码
关机
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
);
});
}
转载请注明原文地址:https://tech.qufami.com/read-2217.html