{"record":{"id":"f98dbc6ed66de933","repo":"mihomo-party-org/clash-party","slug":"admin-restart-detected-but-no-admin-privileges-fou","errorCode":null,"errorMessage":"Admin restart detected but no admin privileges found","messagePattern":"Admin restart detected but no admin privileges found","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/main/core/permissions.ts","lineNumber":399,"sourceCode":"      if (process.platform === 'win32') {\n        const hasAdminPrivileges = await checkAdminPrivileges()\n        if (hasAdminPrivileges) {\n          await patchControledMihomoConfig({ tun: { enable: true }, dns: { enable: true } })\n\n          const autoRunEnabled = await checkAutoRun()\n          if (autoRunEnabled) {\n            await enableAutoRun()\n          }\n\n          await restartCore()\n\n          managerLogger.info('TUN mode auto-enabled after admin restart')\n\n          const { mainWindow } = await import('../index')\n          mainWindow?.webContents.send('controledMihomoConfigUpdated')\n          ipcMain.emit('updateTrayMenu')\n        } else {\n          managerLogger.warn('Admin restart detected but no admin privileges found')\n        }\n      }\n    } catch (error) {\n      managerLogger.error('Failed to auto-enable TUN after admin restart', error)\n    }\n  } else {\n    await validateTunPermissionsOnStartup(restartCore)\n  }\n}\n\nexport function checkTunPermissions(): Promise<boolean> {\n  return checkMihomoCorePermissions()\n}\n\nexport function manualGrantCorePermition(): Promise<void> {\n  return grantTunPermissions()\n}\n","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/mihomo-party-org/clash-party/blob/911e090537acdf7c50bee1c3aebecc2ef119a8b5/src/main/core/permissions.ts#L381-L417","documentation":"checkAdminRestartForTun resumes after an expected elevated relaunch and checks an 'admin restart' marker. This warning is logged when the marker says a restart with admin rights happened, but the current process still lacks admin privileges — so TUN cannot be auto-enabled. It signals the elevation handshake failed or the check ran in the non-elevated instance.","triggerScenarios":"The admin-restart marker/flag exists (e.g. leftover from a previous run or set before relaunch) but isAdmin() returns false in the current process — e.g. UAC elevation was declined, the elevated child failed to start and the normal instance handled the marker, or the marker file was not cleaned up.","commonSituations":"User cancels the OS UAC/admin prompt; on Linux the app was relaunched without sudo; stale marker file persisted from a crash so the next normal launch takes the admin-restart branch.","solutions":["Clear the stale admin-restart marker/flag so normal launches do not enter this branch.","Retry the elevation: trigger checkAdminRestartForTun again and confirm the elevated relaunch actually spawns with admin rights (verify with isAdmin() in the child).","On Linux/macOS ensure the relaunch command genuinely elevates (sudo/pkexec/osascript with administrator privileges)."],"exampleFix":"// before\nif (markerExists) { /* assumes admin */ }\n// after\nif (markerExists) {\n  if (await isAdmin()) {\n    await patchControledMihomoConfig({ tun: { enable: true } })\n  } else {\n    await clearAdminRestartMarker() // avoid stale marker loops\n  }\n}","handlingStrategy":"type-guard","validationCode":"if (!(await isAdmin())) {\n  await clearAdminRestartMarker() // stale marker -> skip auto-enable branch\n  return\n}","typeGuard":"const isAdmin = (): boolean =>\n  process.platform === 'win32'\n    ? /* net session probe or elevation check */ true\n    : typeof process.getuid === 'function' && process.getuid() === 0","tryCatchPattern":"try {\n  await checkAdminRestartForTun()\n} catch (e) {\n  logger.error('admin-restart TUN flow failed', e)\n  await clearAdminRestartMarker()\n}","preventionTips":["Always consume (delete) the admin-restart marker in the elevated instance only.","Verify elevation inside the child process before acting on the marker.","Add an upper bound on restart attempts to avoid elevation loops when users cancel UAC."],"tags":["tun","admin","elevation","restart"],"backgroundTag":"admin-restart-privilege-missing","analyzedSha":"911e090537acdf7c50bee1c3aebecc2ef119a8b5","analyzedAt":"2026-08-30T13:00:49.174Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}