Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
fix schtasks
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Oct 9, 2024
1 parent bb546bd commit cb4dbc2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
8 changes: 2 additions & 6 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
### New Features

- 支持通过代理拉取内置 SubStore 订阅(仅对通过订阅页面Sub-Store图标新导入的订阅有效)
- 支持根据网速快慢旋转悬浮窗图标

### Bug Fixes

- 修复某些 Windows 设备反复提示管理员权限启动的问题
- 修复 macOS 自动更新失败的问题
- 修复某些 Windows 管理员权限依然无法启动的问题
9 changes: 6 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(' '))
Expand All @@ -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()
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/sys/autoRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export async function checkAutoRun(): Promise<boolean> {
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
Expand All @@ -82,7 +84,9 @@ export async function enableAutoRun(): Promise<void> {
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)
Expand Down Expand Up @@ -118,7 +122,7 @@ Categories=Utility;
export async function disableAutoRun(): Promise<void> {
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)
Expand Down
4 changes: 3 additions & 1 deletion src/main/sys/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ const elevateTaskXml = `<?xml version="1.0" encoding="UTF-16"?>
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`
)
}

0 comments on commit cb4dbc2

Please sign in to comment.