Jump to content

Recommended Posts

Posted (edited)

; NetFirewallPolicy2 COM UDF Library for AutoIt3
; AutoIt Version : 3.3.14.5
; Description ...: Windows Firewall Policy2 Interface, Provides access to the firewall policy for Windows Vista+

Including Test Script 

  • _NetFw_Get_CurrentProfileTypes                           Retrieves the currently active firewall profile(s)
  • _NetFw_Get_FirewallEnabled                               Indicates whether a firewall is enabled locally
  • _NetFw_Put_FirewallEnabled                               Specifies whether a firewall is enabled locally
  • _NetFw_Get_ExcludedInterfaces                            Indicates a list of interfaces on which firewall settings are excluded
  • _NetFw_Put_ExcludedInterfaces                            Specifies a list of interfaces on which firewall settings are excluded
  • _NetFw_Get_BlockAllInboundTraffic                        Indicates whether the firewall should not allow inbound traffic
  • _NetFw_Put_BlockAllInboundTraffic                        Specifies whether the firewall should not allow inbound traffic
  • _NetFw_Get_NotificationsDisabled                         Indicates whether interactive firewall notifications are disabled
  • _NetFw_Put_NotificationsDisabled                         Specifies whether interactive firewall notifications are disabled
  • _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled  Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic
  • _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled  Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic
  • _NetFw_Get_Rules                                         Retrieves the interface to collection of firewall rules
  • _NetFw_Get_ServiceRestriction                            Retrieves the interface used to access the Windows Service Hardening store
  • _NetFw_EnableRuleGroup                                   Enables or disables a specified group of firewall rules
  • _NetFw_IsRuleGroupEnabled                                Determines whether a specified group of firewall rules are enabled or disabled for the current profile
  • _NetFw_RestoreLocalFirewallDefaults                      Restores the local firewall configuration to its default state
  • _NetFw_Get_DefaultInboundAction                          Indicates the default action for inbound traffic
  • _NetFw_Put_DefaultInboundAction                          Specifies the default action for inbound traffic
  • _NetFw_Get_DefaultOutboundAction                         Indicates the default action for outbound traffic
  • _NetFw_Put_DefaultOutboundAction                         Specifies the default action for outbound traffic
  • _NetFw_Get_IsRuleGroupCurrentlyEnabled                   Determines whether a specified group of firewall rules are enabled or disabled for the current profile
  • _NetFw_Get_LocalPolicyModifyState                        Determines if adding or setting a rule or group of rules will take effect in the current firewall profile

 

UDF:

  Reveal hidden contents

Test Script:

  Reveal hidden contents

 

Edited by Bilgus
UDF wasn't posted
Posted (edited)

Note: In order to use get/put_ExcludedInterfaces your script must be the same architecture as the underlying OS

so if you are running x64 Windows your script should be x64 as well otherwise it returns random junk

Apparently this is a known bug but MS isn't going to fix it So this udf pops a warning and skips the function

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/85c2bac4-5216-466d-a622-d6806d1a18c5/disabling-firewall-interface-using-inetfwpolicy2-fails-with-windows-64-bits?forum=wfp

Edited by Bilgus
Posted (edited)

Found an Error in __SysFreeString($pBstr)
Should be:

Func __SysFreeString($pBstr)
    DllCall("OleAut32.dll", "NONE", "SysFreeString", "ptr", $pBstr)
    Return SetError(@error, 0, (@error = 0))
EndFunc   ;==>__SysFreeString

Added: _NetFw_Initialize() to allow Initialization or un-initialize interface

Cleaned Up a few things thanks @ptrex

Changed: Initialization func, Switched to wstr directly instead of ptr to wchar in GroupEnabled funcs and SysAllocStringLen

Edited by Bilgus
Posted

This UDF should be adde here:
https://www.autoitscript.com/wiki/User_Defined_Functions#Windows

remark: temporary I can't login to WiKi 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Will do :) 

Edit: Done

Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 4 years later...
Posted

Hello all together :)

Is there a wiki/dokumentation how to use this udf?
Eg.. how to get an Array with all incoming rules?

A short hint would be nice 🙂

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...