From cb4dbc252380278d10c27fc41e94503e03e1031f Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Wed, 9 Oct 2024 16:57:23 +0800 Subject: [PATCH] fix schtasks --- changelog.md | 8 ++------ src/main/index.ts | 9 ++++++--- src/main/sys/autoRun.ts | 10 +++++++--- src/main/sys/misc.ts | 4 +++- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/changelog.md b/changelog.md index 1632dac7..115a116f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,4 @@ -### New Features - -- 支持通过代理拉取内置 SubStore 订阅(仅对通过订阅页面Sub-Store图标新导入的订阅有效) -- 支持根据网速快慢旋转悬浮窗图标 - ### Bug Fixes -- 修复某些 Windows 设备反复提示管理员权限启动的问题 +- 修复 macOS 自动更新失败的问题 +- 修复某些 Windows 管理员权限依然无法启动的问题 diff --git a/src/main/index.ts b/src/main/index.ts index 0b640f6e..6536ec7d 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -25,7 +25,7 @@ export let mainWindow: BrowserWindow | null = null if (process.platform === 'win32' && !is.dev && !process.argv.includes('noadmin')) { try { createElevateTask() - } catch (e) { + } catch (createError) { try { if (process.argv.slice(1).length > 0) { writeFileSync(path.join(taskDir(), 'param.txt'), process.argv.slice(1).join(' ')) @@ -35,10 +35,13 @@ if (process.platform === 'win32' && !is.dev && !process.argv.includes('noadmin') if (!existsSync(path.join(taskDir(), 'mihomo-party-run.exe'))) { throw new Error('mihomo-party-run.exe not found') } else { - execSync('schtasks /run /tn mihomo-party-run') + execSync('C:\\\\Windows\\System32\\schtasks.exe /run /tn mihomo-party-run') } } catch (e) { - dialog.showErrorBox('首次启动请以管理员权限运行', '首次启动请以管理员权限运行') + dialog.showErrorBox( + '首次启动请以管理员权限运行', + `首次启动请以管理员权限运行\n${createError}\n${e}` + ) } finally { app.exit() } diff --git a/src/main/sys/autoRun.ts b/src/main/sys/autoRun.ts index 58902f6b..f50267d7 100644 --- a/src/main/sys/autoRun.ts +++ b/src/main/sys/autoRun.ts @@ -56,7 +56,9 @@ export async function checkAutoRun(): Promise { if (process.platform === 'win32') { const execPromise = promisify(exec) try { - const { stdout } = await execPromise(`chcp 437 && schtasks /query /tn "${appName}"`) + const { stdout } = await execPromise( + `chcp 437 && C:\\\\Windows\\System32\\schtasks.exe /query /tn "${appName}"` + ) return stdout.includes(appName) } catch (e) { return false @@ -82,7 +84,9 @@ export async function enableAutoRun(): Promise { const execPromise = promisify(exec) const taskFilePath = path.join(taskDir(), `${appName}.xml`) await writeFile(taskFilePath, Buffer.from(`\ufeff${taskXml}`, 'utf-16le')) - await execPromise(`schtasks /create /tn "${appName}" /xml "${taskFilePath}" /f`) + await execPromise( + `C:\\\\Windows\\System32\\schtasks.exe /create /tn "${appName}" /xml "${taskFilePath}" /f` + ) } if (process.platform === 'darwin') { const execPromise = promisify(exec) @@ -118,7 +122,7 @@ Categories=Utility; export async function disableAutoRun(): Promise { if (process.platform === 'win32') { const execPromise = promisify(exec) - await execPromise(`schtasks /delete /tn "${appName}" /f`) + await execPromise(`C:\\\\Windows\\System32\\schtasks.exe /delete /tn "${appName}" /f`) } if (process.platform === 'darwin') { const execPromise = promisify(exec) diff --git a/src/main/sys/misc.ts b/src/main/sys/misc.ts index 76d86bb3..f79f7ae2 100644 --- a/src/main/sys/misc.ts +++ b/src/main/sys/misc.ts @@ -108,9 +108,11 @@ const elevateTaskXml = ` export function createElevateTask(): void { const taskFilePath = path.join(taskDir(), `mihomo-party-run.xml`) writeFileSync(taskFilePath, Buffer.from(`\ufeff${elevateTaskXml}`, 'utf-16le')) - execSync(`schtasks /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f`) copyFileSync( path.join(resourcesFilesDir(), 'mihomo-party-run.exe'), path.join(taskDir(), 'mihomo-party-run.exe') ) + execSync( + `C:\\\\Windows\\System32\\schtasks.exe /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f` + ) }