private void tsbsSettings_Click(object sender, EventArgs e) { fSettings fs = new fSettings(); this.Hide(); if (DialogResult.Cancel == fs.ShowDialog()) { fs.Dispose(); } this.Show(); }
private object CheckConfigValue(string selection, string key) { string filePath = Environment.CurrentDirectory + @"\set.dat"; object result; if (File.Exists(filePath)) { try { result = IniFileHelper.ReadValue(selection, key, filePath); if (result != null) { return(result); } } catch { return(null); } return(null); } else { using (fSettings fs = new fSettings()) { this.Hide(); if (DialogResult.Cancel == fs.ShowDialog()) { fs.Dispose(); } this.Show(); result = IniFileHelper.ReadValue(selection, key, filePath); if (result != null) { return(result); } } return(null); } }
private void LoadSettings() { string filePath = Environment.CurrentDirectory + @"\set.dat"; if (File.Exists(filePath)) { sRegex = IniFileHelper.ReadValue("Main", "Regex", filePath); sSucces = IniFileHelper.ReadValue("Main", "Success", filePath); sFailed = IniFileHelper.ReadValue("Main", "Failed", filePath); } else { fSettings fs = new fSettings(); this.Hide(); if (DialogResult.Cancel == fs.ShowDialog()) { fs.Dispose(); } this.Show(); } }
private void FunctExecute(string ip = "", Execut exu = Execut.Add) { string filePath = Environment.CurrentDirectory + @"\set.dat"; if (File.Exists(filePath)) { string sNameRule = IniFileHelper.ReadValue("Firewall", "Name", filePath); string sProtocolRule = IniFileHelper.ReadValue("Firewall", "Protocol", filePath); string sProfileRule = IniFileHelper.ReadValue("Firewall", "Profile", filePath); string sLocalPortRule = IniFileHelper.ReadValue("Firewall", "LocalPort", filePath); string sRemotePortRule = IniFileHelper.ReadValue("Firewall", "RemotePort", filePath); string sAction = IniFileHelper.ReadValue("Firewall", "Action", filePath); string sDir = IniFileHelper.ReadValue("Firewall", "Dir", filePath); if (exu == Execut.Show) { string Command = @"netsh advfirewall firewall show rule name=" + sNameRule; ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + Command); procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false; procStartInfo.CreateNoWindow = true; Process proc = new Process(); procStartInfo.StandardOutputEncoding = Encoding.GetEncoding(866); proc.StartInfo = procStartInfo; proc.Start(); string OutputResult = proc.StandardOutput.ReadToEnd(); AddToLogs(OutputResult, DateTime.Now.ToString(), ""); listBox2.Items.AddRange(ParseOut(OutputResult).ToArray()); } else if (exu == Execut.Add) { string Command = @"netsh advfirewall firewall add rule name=" + sNameRule + " protocol=" + sProtocolRule + " profile=" + sProfileRule + " localport=" + sLocalPortRule + " remoteport=" + sRemotePortRule + " action=" + sAction + " dir=" + sDir + " remoteip=" + ip; ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + Command); procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false; procStartInfo.CreateNoWindow = true; Process proc = new Process(); procStartInfo.StandardOutputEncoding = Encoding.GetEncoding(866); proc.StartInfo = procStartInfo; proc.Start(); string OutputResult = proc.StandardOutput.ReadToEnd(); AddToLogs(OutputResult, DateTime.Now.ToString(), ""); } if (exu == Execut.Delete) { string Command = @"netsh advfirewall firewall delete rule name=" + sNameRule; ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + Command); procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false; procStartInfo.CreateNoWindow = true; Process proc = new Process(); procStartInfo.StandardOutputEncoding = Encoding.GetEncoding(866); proc.StartInfo = procStartInfo; proc.Start(); string OutputResult = proc.StandardOutput.ReadToEnd(); AddToLogs(OutputResult, DateTime.Now.ToString(), ""); } } else { fSettings fs = new fSettings(); this.Hide(); if (DialogResult.Cancel == fs.ShowDialog()) { fs.Dispose(); } this.Show(); } }