1313 Private Sub ResetFirewallButton_Click(sender As Object , e As EventArgs) Handles ResetFirewallButton.Click
1414 Dim resetWindowsFirewallRes As DialogResult = MessageBox.Show( "This will attempt to reset windows firewall to its default state. Confirm action?" , "Reset Windows Firewall" , MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
1515
16- If resetWindowsFirewallRes = DialogResult.Yes Then
17- Try
18- Dim proc As Process = Create_Custom_CMD_Process()
16+ If resetWindowsFirewallRes = DialogResult.No Then
17+ Return
18+ End If
1919
20- proc.StartInfo.Arguments = "/c netsh advfirewall reset"
21- proc.Start()
22- proc.WaitForExit()
20+ Try
21+ Dim proc As Process = Create_Custom_CMD_Process()
2322
24- If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
25- Throw New Exception( "Sdtout: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "Stderr: " + proc.StandardError.ReadToEnd() )
26- End If
23+ proc.StartInfo.Arguments = "/c netsh advfirewall reset"
24+ proc.Start( )
25+ proc.WaitForExit()
2726
28- MessageBox.Show( "Windows firewall reset successful!" , "Reset Windows Firewall" , MessageBoxButtons.OK, MessageBoxIcon.Information)
27+ If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
28+ Throw New Exception( "Sdtout: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "Stderr: " + proc.StandardError.ReadToEnd())
29+ End If
2930
30- proc.Dispose()
31- Catch ex As Exception
32- Log_Exception_To_File(ex, "An error has occurred while resetting windows firewall!" )
31+ MessageBox.Show( "Windows firewall reset successful!" , "Reset Windows Firewall" , MessageBoxButtons.OK, MessageBoxIcon.Information)
3332
34- MessageBox.Show( "An error has occurred while resetting windows firewall!" , "Error" )
35- End Try
36- End If
33+ proc.Dispose()
34+ Catch ex As Exception
35+ Log_Exception_To_File(ex, "An error has occurred while resetting windows firewall!" )
36+
37+ MessageBox.Show( "An error has occurred while resetting windows firewall!" , "Error" )
38+ End Try
3739 End Sub
3840
3941 Private Sub CheckFirewallButton_Click(sender As Object , e As EventArgs) Handles CheckFirewallButton.Click
4042 Dim checkWindowsFirewallRes As DialogResult = MessageBox.Show( "This will attempt to check current state of windows firewall. Confirm action?" , "Check Windows Firewall" , MessageBoxButtons.YesNo, MessageBoxIcon.Information)
4143
42- If checkWindowsFirewallRes = DialogResult.Yes Then
43- Try
44- Dim proc As Process = Create_Custom_CMD_Process()
44+ If checkWindowsFirewallRes = DialogResult.No Then
45+ Return
46+ End If
4547
46- proc.StartInfo.Arguments = "/c netsh advfirewall show allprofiles state"
47- proc.Start()
48- proc.WaitForExit()
48+ Try
49+ Dim proc As Process = Create_Custom_CMD_Process()
4950
50- If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
51- Throw New Exception( "On firewall check" + Environment.NewLine + "StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd() )
52- End If
51+ proc.StartInfo.Arguments = "/c netsh advfirewall show allprofiles state"
52+ proc.Start( )
53+ proc.WaitForExit()
5354
54- If proc.StandardOutput.ReadToEnd().Contains( "OFF" ) Then
55- Dim enableWinFirewallRes As DialogResult = MessageBox.Show( "This will attempt to enable windows firewall. Confirm action?" , "Enable Windows Firewall" , MessageBoxButtons.YesNo, MessageBoxIcon.Information)
55+ If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
56+ Throw New Exception( "On firewall check" + Environment.NewLine + "StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
57+ End If
5658
57- proc.StartInfo.Arguments = "/c netsh advfirewall set allprofiles state on"
58- proc.Start()
59- proc.WaitForExit()
59+ If proc.StandardOutput.ReadToEnd().Contains( "OFF" ) Then
60+ Dim enableWinFirewallRes As DialogResult = MessageBox.Show( "This will attempt to enable windows firewall. Confirm action?" , "Enable Windows Firewall" , MessageBoxButtons.YesNo, MessageBoxIcon.Information)
6061
61- If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
62- Throw New Exception( "On firewall enable" + Environment.NewLine + "StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
63- End If
62+ If enableWinFirewallRes = DialogResult.No Then
63+ Return
64+ End If
6465
65- MessageBox.Show( "Windows firewall profile states successfully enabled!" , "Enable Windows Firewall" , MessageBoxButtons.OK, MessageBoxIcon.Information)
66- Else
67- MessageBox.Show( "Windows firewall profile states are all enabled." , "Windows Firewall Status" , MessageBoxButtons.OK, MessageBoxIcon.Information)
66+ proc.StartInfo.Arguments = "/c netsh advfirewall set allprofiles state on"
67+ proc.Start()
68+ proc.WaitForExit()
69+
70+ If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
71+ Throw New Exception( "On firewall enable" + Environment.NewLine + "StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
6872 End If
6973
70- proc.Dispose()
71- Catch ex As Exception
72- Log_Exception_To_File(ex, "An error has occurred while checking/enabling windows firewall!" )
74+ MessageBox.Show( "Windows firewall profile states successfully enabled!" , "Enable Windows Firewall" , MessageBoxButtons.OK, MessageBoxIcon.Information)
75+ Else
76+ MessageBox.Show( "Windows firewall profile states are all enabled." , "Windows Firewall Status" , MessageBoxButtons.OK, MessageBoxIcon.Information)
77+ End If
7378
74- MessageBox.Show( "An error has occurred while checking/enabling windows firewall!" , "Error" )
75- End Try
76- End If
79+ proc.Dispose()
80+ Catch ex As Exception
81+ Log_Exception_To_File(ex, "An error has occurred while checking/enabling windows firewall!" )
82+
83+ MessageBox.Show( "An error has occurred while checking/enabling windows firewall!" , "Error" )
84+ End Try
7785 End Sub
7886End Class
0 commit comments