WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: stanl on September 09, 2020, 12:30:13 PM

Title: HNetCfg.FwPolicy2 firewall quickie
Post by: stanl on September 09, 2020, 12:30:13 PM
Code (WINBATCH) Select


;Winbatch - find open firewall ports
;===============================================================================================
firewall = CreateObject("HNetCfg.FwPolicy2")
rules = firewall.Rules
output="Name,ApplicationName,LocalPorts,Enabled,Direction":@LF
;for Direction Inbound=1 Outbound =2
;for Enabled -1 = True 0=False
ForEach rule in rules 
   If rule.Action == 0 Then output := rule.Name:",":rule.ApplicationName:",":rule.LocalPorts:",":rule.Enabled:",":rule.Direction:@LF
   ;or display all rules
   ;output := rule.Name:",":rule.ApplicationName:",":rule.LocalPorts:",":rule.Enabled:",":rule.Direction:@LF
Next
Message("Firewall Rules",output)
rules=0
firewall = 0
Exit
;===============================================================================================