From 895b74ca3ff9d78ed1907ee3825061c1e0829be8 Mon Sep 17 00:00:00 2001 From: ezequielnick <107352853+ezequielnick@users.noreply.github.com> Date: Thu, 4 Sep 2025 10:43:46 +0800 Subject: [PATCH] fix: missing admin check logs --- src/main/core/manager.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index 12c250f..c650478 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -541,18 +541,24 @@ export async function checkAdminPrivileges(): Promise { } const execPromise = promisify(exec) - + try { - // 首先尝试 fltmc 命令检测管理员权限 - // 使用 chcp 65001 设置 UTF-8 编码,避免中文乱码 + // fltmc 检测管理员权限 await execPromise('chcp 65001 >nul 2>&1 && fltmc', { encoding: 'utf8' }) + await managerLogger.info('Admin privileges confirmed via fltmc') return true } catch (fltmcError: any) { + const errorCode = fltmcError?.code || 0 + await managerLogger.debug(`fltmc failed with code ${errorCode}, trying net session as fallback`) + try { - // 如果 fltmc 失败,尝试 net session 命令作为备用检测方法 + // net session 备用 await execPromise('chcp 65001 >nul 2>&1 && net session', { encoding: 'utf8' }) + await managerLogger.info('Admin privileges confirmed via net session') return true } catch (netSessionError: any) { + const netErrorCode = netSessionError?.code || 0 + await managerLogger.debug(`Both fltmc and net session failed, no admin privileges. Error codes: fltmc=${errorCode}, net=${netErrorCode}`) return false } } @@ -715,7 +721,6 @@ async function checkHighPrivilegeMihomoProcess(): Promise { for (const executable of mihomoExecutables) { try { - // 使用 UTF-8 编码执行 tasklist 命令 const { stdout } = await execPromise(`chcp 65001 >nul 2>&1 && tasklist /FI "IMAGENAME eq ${executable}" /FO CSV`, { encoding: 'utf8' }) const lines = stdout.split('\n').filter(line => line.includes(executable)) @@ -727,7 +732,6 @@ async function checkHighPrivilegeMihomoProcess(): Promise { if (parts.length >= 2) { const pid = parts[1].replace(/"/g, '').trim() try { - // 使用 UTF-8 编码执行 PowerShell 命令 const { stdout: processInfo } = await execPromise( `powershell -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-Process -Id ${pid} | Select-Object Name,Id,Path,CommandLine | ConvertTo-Json"`, { encoding: 'utf8' }