mirror of
https://github.com/fofolee/uTools-ProcessKiller.git
synced 2025-06-08 14:24:05 +08:00
改用iconv-lite进行解码
This commit is contained in:
parent
23d5a577b0
commit
a071c666de
35
preload.js
35
preload.js
@ -2,7 +2,8 @@ const fs = require('fs');
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const iconExtractor = require('icon-extractor');
|
const iconExtractor = require('icon-extractor');
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const PowerShell = require("powershell");
|
const iconv = require('iconv-lite')
|
||||||
|
const { spawn } = require("child_process")
|
||||||
|
|
||||||
|
|
||||||
getico = tasks =>{
|
getico = tasks =>{
|
||||||
@ -26,11 +27,27 @@ getico = tasks =>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
powershell = (cmd, callback) => {
|
||||||
|
const ps = spawn('powershell', ['-Command', cmd], { encoding: 'buffer' })
|
||||||
|
let chunks = [];
|
||||||
|
let err_chunks = [];
|
||||||
|
ps.stdout.on('data', chunk => {
|
||||||
|
chunks.push(iconv.decode(chunk, 'cp936'))
|
||||||
|
})
|
||||||
|
ps.stderr.on('data', err_chunk => {
|
||||||
|
err_chunks.push(iconv.decode(err_chunk, 'cp936'))
|
||||||
|
})
|
||||||
|
ps.on('close', code => {
|
||||||
|
let stdout = chunks.join("");
|
||||||
|
let stderr = err_chunks.join("");
|
||||||
|
callback(stdout, stderr)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
tasklist = (callback) => {
|
tasklist = (callback) => {
|
||||||
let ps = new PowerShell("chcp 65001;Get-Process | Format-List ProcessName,Path,Description");
|
powershell("Get-Process | Format-List ProcessName,Path,Description", (stdout, stderr) => {
|
||||||
ps.on("output", data => {
|
|
||||||
let tasklist = [];
|
let tasklist = [];
|
||||||
let tasks = data.trim().split('\r\n\r\n');
|
let tasks = stdout.trim().split('\r\n\r\n');
|
||||||
for (var task of tasks) {
|
for (var task of tasks) {
|
||||||
dict = {}
|
dict = {}
|
||||||
let lines = task.split('\r\n')
|
let lines = task.split('\r\n')
|
||||||
@ -52,12 +69,8 @@ tasklist = (callback) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
taskkill = (taskname, taskpath, callback) => {
|
taskkill = (taskname, taskpath, callback) => {
|
||||||
if (taskpath == undefined) {
|
let restart = taskpath == undefined ? '' : `;Start-Process -FilePath "${taskpath}"`;
|
||||||
var ps = new PowerShell(`chcp 65001;Stop-Process -Name ${taskname}`);
|
powershell(`Stop-Process -Name ${taskname}${restart}`, (stdout, stderr) => {
|
||||||
} else {
|
callback(stderr.split('\n')[0])
|
||||||
var ps = new PowerShell(`chcp 65001;Stop-Process -Name ${taskname};Start-Process -FilePath "${taskpath}"`);
|
|
||||||
}
|
|
||||||
ps.on("error-output", data => {
|
|
||||||
callback(data.split('\n')[0])
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user