|
| 1 | +using System.Diagnostics; |
| 2 | +using System.ServiceProcess; |
| 3 | + |
| 4 | +namespace NoVgkInstaller; |
| 5 | + |
| 6 | +internal class Setup |
| 7 | +{ |
| 8 | + public static void TerminateRiotServices() |
| 9 | + { |
| 10 | + string[] riotProcesses = ["RiotClientServices", "LeagueClient", "VALORANT-Win64-Shipping", "Lion-Win64-Shipping"]; |
| 11 | + |
| 12 | + foreach (var processName in riotProcesses) |
| 13 | + { |
| 14 | + try |
| 15 | + { |
| 16 | + var processes = Process.GetProcessesByName(processName); |
| 17 | + |
| 18 | + foreach (var process in processes) |
| 19 | + { |
| 20 | + process.Kill(); |
| 21 | + process.WaitForExit(); |
| 22 | + } |
| 23 | + } |
| 24 | + catch (Exception) |
| 25 | + { |
| 26 | + Console.ForegroundColor = ConsoleColor.DarkYellow; |
| 27 | + Console.WriteLine($" [WARN] Could not terminate {processName}, try running this app as administrator."); |
| 28 | + Console.ResetColor(); |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + internal static bool EnsurevServiceInstalled() |
| 34 | + { |
| 35 | + if (!RemoveVanguard()) |
| 36 | + { |
| 37 | + Console.ForegroundColor = ConsoleColor.Red; |
| 38 | + Console.WriteLine(" [ERROR] Cannot install zombie Vanguard Client because real Vanguard failed to uninstall. Please manually uninstall Vanguard with Revo uninstaller before continuing."); |
| 39 | + Console.ResetColor(); |
| 40 | + return false; |
| 41 | + } |
| 42 | + |
| 43 | + try |
| 44 | + { |
| 45 | + if (ServiceController.GetServices().Any(s => s.ServiceName == "vgc")) |
| 46 | + return true; |
| 47 | + |
| 48 | + Console.WriteLine(" [INFO] Registering vService.exe..."); |
| 49 | + |
| 50 | + string exePath = Path.Combine(AppContext.BaseDirectory, "vService.exe"); |
| 51 | + |
| 52 | + if (!File.Exists(exePath)) |
| 53 | + { |
| 54 | + Console.ForegroundColor = ConsoleColor.Red; |
| 55 | + Console.WriteLine($" [ERROR] vService.exe not found in {exePath}"); |
| 56 | + Console.ResetColor(); |
| 57 | + return false; |
| 58 | + } |
| 59 | + |
| 60 | + string scCreate = $"sc create vgc binPath= \"{exePath}\" start= demand DisplayName= \"vService\""; |
| 61 | + string scSdset = "sc sdset vgc D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)" + |
| 62 | + "(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)" + |
| 63 | + "(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)" + |
| 64 | + "(A;;RPLOCRRC;;;S-1-5-32-545)"; |
| 65 | + |
| 66 | + var psi = new ProcessStartInfo |
| 67 | + { |
| 68 | + FileName = "cmd.exe", |
| 69 | + Arguments = $"/c \"{scCreate} && {scSdset}\"", |
| 70 | + Verb = "runas", |
| 71 | + UseShellExecute = true, |
| 72 | + WindowStyle = ProcessWindowStyle.Hidden |
| 73 | + }; |
| 74 | + |
| 75 | + using var process = Process.Start(psi); |
| 76 | + process?.WaitForExit(); |
| 77 | + |
| 78 | + bool serviceExists = ServiceController.GetServices().Any(s => s.ServiceName == "vgc"); |
| 79 | + if (serviceExists) |
| 80 | + { |
| 81 | + Console.ForegroundColor = ConsoleColor.Green; |
| 82 | + Console.WriteLine(" [SUCCESS] vService successfully registered."); |
| 83 | + Console.ResetColor(); |
| 84 | + return true; |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + Console.ForegroundColor = ConsoleColor.Red; |
| 89 | + Console.WriteLine(" [ERROR] Failed to register vService."); |
| 90 | + Console.ResetColor(); |
| 91 | + return false; |
| 92 | + } |
| 93 | + } |
| 94 | + catch (Exception ex) |
| 95 | + { |
| 96 | + Console.ForegroundColor = ConsoleColor.Red; |
| 97 | + Console.WriteLine($" [ERROR] Failed to create or verify zombie Vanguard Client registration: {ex.Message}"); |
| 98 | + Console.ResetColor(); |
| 99 | + return false; |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + public static bool RemoveVanguard() |
| 104 | + { |
| 105 | + string vgkpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Riot Vanguard", "installer.exe"); |
| 106 | + |
| 107 | + if (!File.Exists(vgkpath)) |
| 108 | + { |
| 109 | + return true; |
| 110 | + } |
| 111 | + |
| 112 | + try |
| 113 | + { |
| 114 | + using var process = Process.Start(vgkpath, "--quiet"); |
| 115 | + if (process != null) |
| 116 | + { |
| 117 | + Console.WriteLine(" [INFO] Attempting to uninstall Vanguard..."); |
| 118 | + |
| 119 | + process.WaitForExit(); |
| 120 | + Thread.Sleep(5000); |
| 121 | + |
| 122 | + for (int i = 0; i < 30; i++) |
| 123 | + { |
| 124 | + if (!File.Exists(vgkpath)) |
| 125 | + { |
| 126 | + Console.ForegroundColor = ConsoleColor.Green; |
| 127 | + Console.WriteLine(" [SUCCESS] Vanguard uninstallation completed, starting now..."); |
| 128 | + Console.ResetColor(); |
| 129 | + return true; |
| 130 | + } |
| 131 | + |
| 132 | + Thread.Sleep(1000); |
| 133 | + } |
| 134 | + |
| 135 | + Console.ForegroundColor = ConsoleColor.DarkYellow; |
| 136 | + Console.WriteLine(" [WARN] Vanguard uninstallation failed, try running this app as administrator."); |
| 137 | + Console.ResetColor(); |
| 138 | + return false; |
| 139 | + } |
| 140 | + else |
| 141 | + { |
| 142 | + Console.ForegroundColor = ConsoleColor.Red; |
| 143 | + Console.WriteLine(" [ERROR] Failed to start Vanguard uninstallation process."); |
| 144 | + Console.ResetColor(); |
| 145 | + return false; |
| 146 | + } |
| 147 | + } |
| 148 | + catch (Exception ex) |
| 149 | + { |
| 150 | + Console.ForegroundColor = ConsoleColor.Red; |
| 151 | + Console.WriteLine($" [ERROR] Vanguard uninstallation aborted: {ex}"); |
| 152 | + Console.ResetColor(); |
| 153 | + return false; |
| 154 | + } |
| 155 | + } |
| 156 | +} |
0 commit comments