fix systemroot path

#328
This commit is contained in:
pompurin404 2024-11-11 11:24:21 +08:00
parent b38bd8d1f8
commit 94c126b601
No known key found for this signature in database
3 changed files with 5 additions and 5 deletions

View File

@ -36,7 +36,7 @@ if (process.platform === 'win32' && !is.dev && !process.argv.includes('noadmin')
if (!existsSync(path.join(taskDir(), 'mihomo-party-run.exe'))) { if (!existsSync(path.join(taskDir(), 'mihomo-party-run.exe'))) {
throw new Error('mihomo-party-run.exe not found') throw new Error('mihomo-party-run.exe not found')
} else { } else {
execSync('C:\\\\Windows\\System32\\schtasks.exe /run /tn mihomo-party-run') execSync('%SystemRoot%\\System32\\schtasks.exe /run /tn mihomo-party-run')
} }
} catch (e) { } catch (e) {
let createErrorStr = `${createError}` let createErrorStr = `${createError}`

View File

@ -54,7 +54,7 @@ export async function checkAutoRun(): Promise<boolean> {
const execPromise = promisify(exec) const execPromise = promisify(exec)
try { try {
const { stdout } = await execPromise( 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) return stdout.includes(appName)
} catch (e) { } catch (e) {
@ -82,7 +82,7 @@ export async function enableAutoRun(): Promise<void> {
const taskFilePath = path.join(taskDir(), `${appName}.xml`) const taskFilePath = path.join(taskDir(), `${appName}.xml`)
await writeFile(taskFilePath, Buffer.from(`\ufeff${taskXml}`, 'utf-16le')) await writeFile(taskFilePath, Buffer.from(`\ufeff${taskXml}`, 'utf-16le'))
await execPromise( 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') { if (process.platform === 'darwin') {
@ -119,7 +119,7 @@ Categories=Utility;
export async function disableAutoRun(): Promise<void> { export async function disableAutoRun(): Promise<void> {
if (process.platform === 'win32') { if (process.platform === 'win32') {
const execPromise = promisify(exec) 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') { if (process.platform === 'darwin') {
const execPromise = promisify(exec) const execPromise = promisify(exec)

View File

@ -109,6 +109,6 @@ export function createElevateTask(): void {
path.join(taskDir(), 'mihomo-party-run.exe') path.join(taskDir(), 'mihomo-party-run.exe')
) )
execSync( 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`
) )
} }