Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new way to kill off service #717

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions lib/conf/tasks/os/windows.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use strict";

const { exec } = require('child_process');
const path = require('path');

var fs = require('fs'),
join = require('path').join,
firewall = require('firewall'),
Expand Down Expand Up @@ -40,15 +43,30 @@ function remove_firewall_rules(cb) {
}

function terminate_if_running(cb) {
var pidfile = join(paths.temp, 'prey.pid');
fs.readFile(pidfile, function(err, pid) {
if (err) return cb();

try { process.kill(parseInt(pid)) } catch(e) { /* nah, never mind */ }
cb()
})
exec("sc delete CronService", () => {
exec("taskkill /f /im wpxsvc.exe", () => {
var pidfile = join(paths.temp, 'prey.pid');
fs.readFile(pidfile, function(err, pid) {
if (err) {
delete_node_service();
return cb();
}
try {
process.kill(parseInt(pid));
delete_node_service();
} catch(e) {
delete_node_service();
}
cb();
});
});
});
}

const delete_node_service = () => {
exec(`wmic process where "ExecutablePath='${paths.install}\\current\\bin\\node.exe'" delete`, () => {});
};

exports.post_install = function(cb) {
cb();
};
Expand Down