| | | 1 | | using System.Diagnostics; |
| | | 2 | | |
| | | 3 | | namespace SwitchBlade.Services |
| | | 4 | | { |
| | | 5 | | public static class RestartLogic |
| | | 6 | | { |
| | | 7 | | public static ProcessStartInfo BuildRestartStartInfo(string processPath, string currentWorkingDirectory, int cur |
| | 3 | 8 | | { |
| | | 9 | | // Determine if we're de-elevating (currently admin, turning it off) |
| | | 10 | | // If we are currently elevated (isElevated = true), we assume the intention of a generic restart |
| | | 11 | | // is to return to the logical "default" state or just restart. |
| | | 12 | | // However, the original logic specifically had a check: bool isDeElevating = Program.IsRunningAsAdmin(); |
| | | 13 | | // And then it had two branches. |
| | | 14 | | // Branch 1 (isDeElevating == true): Uses mixed mode with explorer.exe to de-elevate? |
| | | 15 | | // Actually, let's look at the original code carefully: |
| | | 16 | | // "bool isDeElevating = Program.IsRunningAsAdmin();" |
| | | 17 | | // This variable name implies that if we ARE admin, we are treating this restart as a "de-elevation" attempt |
| | | 18 | | // or at least a restart that might need to handle the admin context carefully. |
| | | 19 | | // |
| | | 20 | | // Original Code: |
| | | 21 | | // if (isDeElevating) { |
| | | 22 | | // command = Wait-Process... Start-Process explorer.exe -ArgumentList 'escapedPath' |
| | | 23 | | // } else { |
| | | 24 | | // command = Wait-Process... Start-Process 'processPath' |
| | | 25 | | // } |
| | | 26 | | // |
| | | 27 | | // The logic seems to be: If we are admin, launch via explorer to essentially de-elevate (since explorer is |
| | | 28 | | |
| | 3 | 29 | | if (isElevated) |
| | 2 | 30 | | { |
| | 2 | 31 | | var escapedPath = processPath.Replace("\"", "`\""); |
| | 2 | 32 | | var command = $"Wait-Process -Id {currentPid} -ErrorAction SilentlyContinue; Start-Process explorer.exe |
| | | 33 | | |
| | 2 | 34 | | return new ProcessStartInfo |
| | 2 | 35 | | { |
| | 2 | 36 | | FileName = "powershell.exe", |
| | 2 | 37 | | Arguments = $"-NoProfile -WindowStyle Hidden -Command \"{command}\"", |
| | 2 | 38 | | UseShellExecute = false, |
| | 2 | 39 | | CreateNoWindow = true, |
| | 2 | 40 | | WorkingDirectory = currentWorkingDirectory |
| | 2 | 41 | | }; |
| | | 42 | | } |
| | | 43 | | else |
| | 1 | 44 | | { |
| | 1 | 45 | | var command = $"Wait-Process -Id {currentPid} -ErrorAction SilentlyContinue; Start-Process '{processPath |
| | | 46 | | |
| | 1 | 47 | | return new ProcessStartInfo |
| | 1 | 48 | | { |
| | 1 | 49 | | FileName = "powershell.exe", |
| | 1 | 50 | | Arguments = $"-NoProfile -WindowStyle Hidden -Command \"{command}\"", |
| | 1 | 51 | | UseShellExecute = false, |
| | 1 | 52 | | CreateNoWindow = true, |
| | 1 | 53 | | WorkingDirectory = currentWorkingDirectory |
| | 1 | 54 | | }; |
| | | 55 | | } |
| | 3 | 56 | | } |
| | | 57 | | } |
| | | 58 | | } |