-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathadvfirewall-pause.ps1
More file actions
55 lines (47 loc) · 2.4 KB
/
Copy pathadvfirewall-pause.ps1
File metadata and controls
55 lines (47 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
if ($PSVersionTable.PSVersion.Major -lt 3) {
[string] $PSScriptRoot = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
}
if ($PSVersionTable.PSVersion.Major -lt 3) {
[string] $PSCommandPath = $MyInvocation.MyCommand.Definition
}
$Administrator = (
[Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole(
[Security.Principal.WindowsBuiltInRole] "Administrator"
)
if (-not $Administrator) {
Start-Process -FilePath "powershell" -WindowStyle Hidden -WorkingDirectory $PSScriptRoot -Verb runAs `
-ArgumentList "-ExecutionPolicy Bypass -File $PSCommandPath $args"
return
}
Import-LocalizedData -BaseDirectory $PSScriptRoot\Locales -BindingVariable Messages
Import-Module -Name (Join-Path -Path $PSScriptRoot\Modules -ChildPath Show-Balloon)
if (Get-Command -Name Get-NetFirewallRule -ErrorAction SilentlyContinue) {
Set-NetFirewallProfile -DefaultInboundAction Allow `
-DefaultOutboundAction Allow `
-All
} else {
Write-Warning -Message $Messages."Get-NetFirewallRule not supported, using Netsh."
Start-Process -FilePath "netsh" `
-ArgumentList ("advfirewall", "set", "allprofiles", "firewallpolicy", "allowinbound,allowoutbound") `
-WindowStyle Hidden -Wait
}
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Result = [System.Windows.Forms.MessageBox]::Show(
$Messages."Warning! Windows Firewall has been stopped, select OK to restore the previous state.",
"Windows Firewall", 0, [System.Windows.Forms.MessageBoxIcon]::Error
)
if ($Result -eq "OK") {
if (Get-Command -Name Get-NetFirewallRule -ErrorAction SilentlyContinue) {
Set-NetFirewallProfile -DefaultInboundAction Block `
-DefaultOutboundAction Block `
-All
} else {
Write-Warning -Message $Messages."Get-NetFirewallRule not supported, using Netsh."
Start-Process -FilePath "netsh" `
-ArgumentList ("advfirewall", "set", "allprofiles", "firewallpolicy", "blockinbound,blockoutbound") `
-WindowStyle Hidden -Wait
}
Show-Balloon -TipTitle "Windows Firewall" -TipText $Messages."Windows Firewall turned back on." `
-TipIcon "Info" -Icon "$env:SystemRoot\system32\FirewallControlPanel.dll"
}