mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
fix: resolve Windows admin mode restart issue
This commit is contained in:
parent
b5f6658b72
commit
8cfee2f5e5
@ -361,24 +361,34 @@ export async function restartAsAdmin(): Promise<void> {
|
|||||||
throw new Error('This function is only available on Windows')
|
throw new Error('This function is only available on Windows')
|
||||||
}
|
}
|
||||||
|
|
||||||
const execPromise = promisify(exec)
|
|
||||||
const exePath = process.execPath
|
const exePath = process.execPath
|
||||||
const args = process.argv.slice(1)
|
const args = process.argv.slice(1)
|
||||||
|
const restartArgs = [...args, '--admin-restart-for-tun']
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const restartArgs = [...args, '--admin-restart-for-tun']
|
// 处理路径和参数的引号
|
||||||
const escapedExePath = exePath.replace(/'/g, "''")
|
const escapedExePath = exePath.replace(/'/g, "''")
|
||||||
const escapedArgs = restartArgs.map(arg => `'${arg.replace(/'/g, "''")}'`).join(', ')
|
const argsString = restartArgs.map(arg => arg.replace(/'/g, "''")).join("', '")
|
||||||
|
|
||||||
let command: string
|
let command: string
|
||||||
if (restartArgs.length > 0) {
|
if (restartArgs.length > 0) {
|
||||||
command = `powershell -WindowStyle Hidden -Command "Start-Process -FilePath '${escapedExePath}' -ArgumentList ${escapedArgs} -Verb RunAs"`
|
command = `powershell -Command "Start-Process -FilePath '${escapedExePath}' -ArgumentList '${argsString}' -Verb RunAs"`
|
||||||
} else {
|
} else {
|
||||||
command = `powershell -WindowStyle Hidden -Command "Start-Process -FilePath '${escapedExePath}' -Verb RunAs"`
|
command = `powershell -Command "Start-Process -FilePath '${escapedExePath}' -Verb RunAs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Restarting as administrator with command:', command)
|
console.log('Restarting as administrator with command:', command)
|
||||||
await execPromise(command, { windowsHide: true })
|
|
||||||
|
// 执行PowerShell命令
|
||||||
|
exec(command, { windowsHide: true }, (error, _stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.error('PowerShell execution error:', error)
|
||||||
|
console.error('stderr:', stderr)
|
||||||
|
} else {
|
||||||
|
console.log('PowerShell command executed successfully')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 1500))
|
await new Promise(resolve => setTimeout(resolve, 1500))
|
||||||
|
|
||||||
const { app } = await import('electron')
|
const { app } = await import('electron')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user