From 94c126b601417ed6577b00f0a4fb1ac031eb88d4 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Mon, 11 Nov 2024 11:24:21 +0800 Subject: [PATCH] fix systemroot path #328 --- src/main/index.ts | 2 +- src/main/sys/autoRun.ts | 6 +++--- src/main/sys/misc.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 72f8e96..6b43839 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -36,7 +36,7 @@ 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('C:\\\\Windows\\System32\\schtasks.exe /run /tn mihomo-party-run') + execSync('%SystemRoot%\\System32\\schtasks.exe /run /tn mihomo-party-run') } } catch (e) { let createErrorStr = `${createError}` diff --git a/src/main/sys/autoRun.ts b/src/main/sys/autoRun.ts index 513261d..822ecec 100644 --- a/src/main/sys/autoRun.ts +++ b/src/main/sys/autoRun.ts @@ -54,7 +54,7 @@ export async function checkAutoRun(): Promise { const execPromise = promisify(exec) try { const { stdout } = await execPromise( - `chcp 437 && C:\\\\Windows\\System32\\schtasks.exe /query /tn "${appName}"` + `chcp 437 && %SystemRoot%\\System32\\schtasks.exe /query /tn "${appName}"` ) return stdout.includes(appName) } catch (e) { @@ -82,7 +82,7 @@ export async function enableAutoRun(): Promise { const taskFilePath = path.join(taskDir(), `${appName}.xml`) await writeFile(taskFilePath, Buffer.from(`\ufeff${taskXml}`, 'utf-16le')) await execPromise( - `C:\\\\Windows\\System32\\schtasks.exe /create /tn "${appName}" /xml "${taskFilePath}" /f` + `%SystemRoot%\\System32\\schtasks.exe /create /tn "${appName}" /xml "${taskFilePath}" /f` ) } if (process.platform === 'darwin') { @@ -119,7 +119,7 @@ Categories=Utility; export async function disableAutoRun(): Promise { if (process.platform === 'win32') { const execPromise = promisify(exec) - await execPromise(`C:\\\\Windows\\System32\\schtasks.exe /delete /tn "${appName}" /f`) + await execPromise(`%SystemRoot%\\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 07dc442..ceed928 100644 --- a/src/main/sys/misc.ts +++ b/src/main/sys/misc.ts @@ -109,6 +109,6 @@ export function createElevateTask(): void { path.join(taskDir(), 'mihomo-party-run.exe') ) execSync( - `C:\\\\Windows\\System32\\schtasks.exe /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f` + `%SystemRoot%\\System32\\schtasks.exe /create /tn "mihomo-party-run" /xml "${taskFilePath}" /f` ) }