Found this Powershell Script. Should make things easier.
Copy/paste the script into Notepad (or similar) and save the file as: fw.ps1
function isFirewallPortOpen {
param( [int] $port )
$fw = New-Object -ComObject hnetcfg.fwpolicy2
if ($fw.Rules | Where {$_.LocalPorts -eq $port }) {
return [bool]$true
} else {
return [bool]$false
}
}
function existsFirewallRule {
param( [string] $name )
$fw = New-Object -ComObject hnetcfg.fwpolicy2
if ($fw.Rules | Where { $_.Name -eq $name }) {
return [bool]$true
} else {
return [bool]$false
}
}
function addFirewallRule {
param(
[string] $name,
[int] $port,
[int] $protocol
)
$fw = New-Object -ComObject hnetcfg.fwpolicy2
if (isFirewallPortOpen $port -or existsFirewallRule $name) {
Write-Host -ForegroundColor:Red "**Rule Already Exists or Port Already Open."
} else {
$rule = New-Object -ComObject HNetCfg.FWRule
$rule.Name = $name
$rule.Protocol = $protocol
# NET_FW_IP_PROTOCOL_TCP = 6
# NET_FW_IP_PROTOCOL_UDP = 17
$rule.LocalPorts = $port
$rule.Enabled = $true
#$rule.Grouping = "SambaPOS Multi-terminal"
$rule.Profiles = 2
# NET_FW_PROFILE2_DOMAIN = 1
# NET_FW_PROFILE2_PRIVATE = 2
# NET_FW_PROFILE2_PUBLIC = 4
# NET_FW_PROFILE2_ALL = 7
$rule.Action = 1 # NET_FW_ACTION_ALLOW
$rule.EdgeTraversal = $false
$fw.Rules.Add($rule)
Write-Host -ForegroundColor:Blue "A rule named '$name' has been added to Windows' Firewall."
}
}
addFirewallRule -name:"SambaPOS SQL Traffic" -port:1433 -protocol:6
addFirewallRule -name:"SambaPOS SQL Browser Traffic" -port:1434 -protocol:17
addFirewallRule -name:"SambaPOS Messaging Server" -port:9898 -protocol:6
The last 3 lines of the script execute to add 3 Inbound Rules to the Firewall. Change the name of the Rule or the port if desired.
Open a Command Prompt as Administrator and navigate to the location of the fw.ps1
file. In the Command Window, type the following to execute the script:
powershell -executionpolicy bypass -File fw.ps1
This screenshot shows what happens when it is successful, and what happens if it is run when the Rule or Protocol/Port already exist in the Firewall.
And here, we see 3 Rules have been created: