private void button_Click(object sender, EventArgs e) { // Make sure the file exists before trying to launch it if (!File.Exists(Directory.GetCurrentDirectory() + "\\dnscrypt-proxy.exe")) { MessageBox.Show("dnscrypt-proxy.exe was not found. It should be placed in the same directory as this program. If you do not have this file, you can download it from http://dnscrypt.org", "File not found"); return; } this.cryptProc = new ProcessStartInfo(); this.cryptProc.FileName = "dnscrypt-proxy.exe"; this.cryptProc.WindowStyle = ProcessWindowStyle.Minimized; if (serviceConfigured) { // Stop running DNSCrypt service ServiceMgr serviceMgr = new ServiceMgr(); ServiceMgr.stopService("dnscrypt-proxy", 1000); // Remove service (run dnscrypt-proxy --uninstall) this.cryptProc.Arguments = " --uninstall"; this.statusLabel.Text = "Uninstalling"; // "dnscrypt-proxy.exe --uninstall" takes care of removing everything from registry. We don't need to do anything there. } else { // Install service (run dnscrypt-proxy --install) this.cryptProc.Arguments = " -R \"" + this.name + "\" -L \"" + Directory.GetCurrentDirectory() + "\\dnscrypt-resolvers.csv\" --install"; this.statusLabel.Text = "Installing"; if (this.protoTCP.Checked) { Registry.SetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\dnscrypt-proxy\\Parameters", "TCPOnly", "1", RegistryValueKind.DWord); } } // Update visuals this.button.Enabled = false; this.statusLabel.ForeColor = Color.DarkOrange; // Run dnscrypt-proxy this.cryptHandle = Process.Start(this.cryptProc); // Wait for a second DateTime Tthen = DateTime.Now; do { Application.DoEvents(); }while (Tthen.AddSeconds(1) > DateTime.Now); // Doublecheck that dnscrypt-proxy actually removed the service, if trying to remove the serice object dnsCryptReg = Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\dnscrypt-proxy", "DisplayName", ""); if (dnsCryptReg != null && serviceConfigured) { MessageBox.Show("It was not possible to disable the DNSCrypt system service.", "Error"); } // Doublecheck that dnscrypt-proxy actually installed the service, if trying to install the serice if (dnsCryptReg == null && !serviceConfigured) { MessageBox.Show("It was not possible to enable the DNSCrypt system service. Make sure this program is running with Administrator privileges.", "Error"); } // Update UI and status this.checkStatus(); }
private void button_Click(object sender, EventArgs e) { // Make sure the file exists before trying to launch it if (!File.Exists(Directory.GetCurrentDirectory() + "\\dnscrypt-proxy.exe")) { MessageBox.Show("dnscrypt-proxy.exe was not found. It should be placed in the same directory as this program. If you do not have this file, you can download it from http://dnscrypt.org", "File not found"); return; } this.cryptProc = new ProcessStartInfo(); this.cryptProc.FileName = "dnscrypt-proxy.exe"; this.cryptProc.WindowStyle = ProcessWindowStyle.Minimized; if (serviceConfigured) { // Stop running DNSCrypt service ServiceMgr serviceMgr = new ServiceMgr(); ServiceMgr.stopService("dnscrypt-proxy", 1000); // Remove service (run dnscrypt-proxy --uninstall) this.cryptProc.Arguments = " --uninstall"; this.statusLabel.Text = "Uninstalling"; // "dnscrypt-proxy.exe --uninstall" takes care of removing everything from registry. We don't need to do anything there. } else { // Install service (run dnscrypt-proxy --install) this.cryptProc.Arguments = " -R \"" + this.name + "\" -L \"" + Directory.GetCurrentDirectory() + "\\dnscrypt-resolvers.csv\" --install"; this.statusLabel.Text = "Installing"; if (this.protoTCP.Checked) { Registry.SetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\dnscrypt-proxy\\Parameters", "TCPOnly", "1", RegistryValueKind.DWord); } } // Update visuals this.button.Enabled = false; this.statusLabel.ForeColor = Color.DarkOrange; // Run dnscrypt-proxy this.cryptHandle = Process.Start(this.cryptProc); // Wait for a second DateTime Tthen = DateTime.Now; do { Application.DoEvents(); } while (Tthen.AddSeconds(1) > DateTime.Now); // Doublecheck that dnscrypt-proxy actually removed the service, if trying to remove the serice object dnsCryptReg = Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\dnscrypt-proxy", "DisplayName", ""); if (dnsCryptReg != null && serviceConfigured) { MessageBox.Show("It was not possible to disable the DNSCrypt system service.", "Error"); } // Doublecheck that dnscrypt-proxy actually installed the service, if trying to install the serice if (dnsCryptReg == null && !serviceConfigured) { MessageBox.Show("It was not possible to enable the DNSCrypt system service. Make sure this program is running with Administrator privileges.", "Error"); } // Update UI and status this.checkStatus(); }