fix: migrate from WMIC to modern APIs and improve privilege checks (#945)

* fix: WMIC is deprecated on windows-latest

* opt: remove WMIC

* fix: correctly detect high-privilege processes
This commit is contained in:
Memory 2025-08-14 09:54:54 +08:00 committed by GitHub
parent 348c429855
commit 35f51e1e39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -518,10 +518,11 @@ async function checkHighPrivilegeMihomoProcess(): Promise<boolean> {
if (parts.length >= 2) {
const pid = parts[1].replace(/"/g, '').trim()
try {
const { stdout: processInfo } = await execPromise(`wmic process where "ProcessId=${pid}" get Name,ProcessId,ExecutablePath,CommandLine /format:csv`)
const { stdout: processInfo } = await execPromise(`powershell -Command "Get-Process -Id ${pid} | Select-Object Name,Id,Path,CommandLine | ConvertTo-Json"`)
const processJson = JSON.parse(processInfo)
await managerLogger.info(`Process ${pid} info: ${processInfo.substring(0, 200)}`)
if (processInfo.includes('mihomo')) {
if (processJson.Name === "mihomo" && processJson.Path === null) {
return true
}
} catch (error) {