Jump to content
Bilgus

Windows Firewall Policy2 Interface UDF, Provides access to the firewall policy for Windows Vista+

Recommended Posts

Bilgus
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:

Spoiler
;INetFwPolicy2COM.au3
#include-once
;#RequireAdmin

#include <WinAPIConstants.au3> ; $S_OK, $E_NOINTERFACE, $E_NOTIMPL
#include <WinAPIMisc.au3> ; _WinAPI_GetString


; #INDEX# ========================================================================================================================================================================
; Title .........: 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+
; Author(s) .....: Bilgus 2018
; ================================================================================================================================================================================
#Region Global Variables and Constants
Global $__g_oINetFwPolicy2

; #CONSTANTS# ====================================================================================================================================================================
Global Enum $NET_FW_PROFILE2_DOMAIN = 0x1, $NET_FW_PROFILE2_PRIVATE = 0x2, $NET_FW_PROFILE2_PUBLIC = 0x4, $NET_FW_PROFILE2_ALL = 0x7FFFFFFF
Global Enum $NET_FW_MODIFY_STATE_OK = 0x0, $NET_FW_MODIFY_STATE_GP_OVERRIDE, $NET_FW_MODIFY_STATE_INBOUND_BLOCKED
Global Enum $NET_FW_ACTION_BLOCK = 0x0, $NET_FW_ACTION_ALLOW, $NET_FW_ACTION_MAX

; #INTERNAL CONSTANTS#============================================================================================================================================================
Global Enum $NET_FW_VARIANT_TRUE = -1, $NET_FW_VARIANT_FALSE = False ;A value 0 will be equal to Boolean False, Any other number value will be equal to Boolean True
Global Enum $NET_FW_VT_VARIANT = 0x000C, $NET_FW_VT_ARRAY = 0x2000, $NET_FW_VT_BSTR = 0x0008
Global Const $NET_FW_UNKNOWNERROR = 0xE

Global Const $dtag_INetFwPolicy2 = _ ; Inherits from IDispatch.
        "GetTypeInfoCount hresult(dword*);" & _ ; Retrieves the number of type information interfaces that an object provides (either 0 or 1).
        "GetTypeInfo hresult(dword;dword;ptr*);" & _ ; Gets the type information for an object.
        "GetIDsOfNames hresult(ptr;ptr;dword;dword;ptr);" & _ ; Maps a single member and an optional set of argument names to a corresponding set of integer DISPIDs, which can be used on subsequent calls to Invoke.
        "Invoke hresult(dword;ptr;dword;word;ptr;ptr;ptr;ptr);" & _ ; Provides access to properties and methods exposed by an object.
        "" & _ ;Endof IDispatch
        "get_CurrentProfileTypes          hresult(long*;);" & _ ;Retrieves the currently active firewall profile(s)
        "get_FirewallEnabled              hresult(int;short*);" & _ ;Indicates whether a firewall is enabled locally
        "put_FirewallEnabled              hresult(int;short);" & _ ;Specifies whether a firewall is enabled locally
        "get_ExcludedInterfaces           hresult(int;ptr);" & _ ;Indicates a list of interfaces on which firewall settings are excluded
        "put_ExcludedInterfaces           hresult(int;ptr);" & _ ;Specifies a list of interfaces on which firewall settings are excluded
        "get_BlockAllInboundTraffic       hresult(int;short*);" & _ ;Indicates whether the firewall should not allow inbound traffic
        "put_BlockAllInboundTraffic       hresult(int;short);" & _ ;Specifies whether the firewall should not allow inbound traffic
        "get_NotificationsDisabled        hresult(int;short*);" & _ ;Indicates whether interactive firewall notifications are disabled
        "put_NotificationsDisabled        hresult(int;short);" & _ ;Specifies whether interactive firewall notifications are disabled
        "get_UnicastResponsesToMulticastBroadcastDisabled        hresult(int;short*);" & _ ;Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic
        "put_UnicastResponsesToMulticastBroadcastDisabled        hresult(int;short);" & _ ;Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic
        "get_Rules                        hresult(ptr);" & _ ;Retrieves the interface to collection of firewall rules
        "get_ServiceRestriction           hresult(ptr);" & _ ;Retrieves the interface used to access the Windows Service Hardening store
        "EnableRuleGroup                  hresult(long;wstr;short);" & _ ;Enables or disables a specified group of firewall rules
        "IsRuleGroupEnabled               hresult(long;wstr;short*);" & _ ;Determines whether a specified group of firewall rules are enabled or disabled for the current profile
        "RestoreLocalFirewallDefaults     hresult();" & _ ;Restores the local firewall configuration to its default state
        "get_DefaultInboundAction         hresult(int;int*);" & _ ;Indicates the default action for inbound traffic
        "put_DefaultInboundAction         hresult(int;int);" & _ ;Specifies the default action for inbound traffic
        "get_DefaultOutboundAction        hresult(int;int*);" & _ ;Indicates the default action for outbound traffic
        "put_DefaultOutboundAction        hresult(int;int);" & _ ;Specifies the default action for outbound traffic
        "get_IsRuleGroupCurrentlyEnabled  hresult(wstr;short*);" & _ ;Determines whether a specified group of firewall rules are enabled or disabled for the current profile
        "get_LocalPolicyModifyState       hresult(int*);" ;Determines if adding or setting a rule or group of rules will take effect in the current firewall profile
; ================================================================================================================================================================================
#EndRegion Global Variables and Constants


#Region Public NetProfile2_Functions
; #CURRENT# ======================================================================================================================================================================
;  _NetFw_EnableRuleGroup
;  _NetFw_Get_BlockAllInboundTraffic
;  _NetFw_Get_CurrentProfileTypes
;  _NetFw_Get_DefaultInboundAction
;  _NetFw_Get_DefaultOutboundAction
;  _NetFw_Get_ExcludedInterfaces
;  _NetFw_Get_FirewallEnabled
;  _NetFw_Get_IsRuleGroupCurrentlyEnabled
;  _NetFw_Get_LocalPolicyModifyState
;  _NetFw_Get_NotificationsDisabled
;  _NetFw_Get_Rules
;  _NetFw_Get_ServiceRestriction
;  _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled
;  _NetFw_Initialize
;  _NetFw_IsRuleGroupEnabled
;  _NetFw_Put_BlockAllInboundTraffic
;  _NetFw_Put_DefaultInboundAction
;  _NetFw_Put_DefaultOutboundAction
;  _NetFw_Put_ExcludedInterfaces
;  _NetFw_Put_FirewallEnabled
;  _NetFw_Put_NotificationsDisabled
;  _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled
;  _NetFw_RestoreLocalFirewallDefaults
; ================================================================================================================================================================================
; #INTERNAL FUNCTIONS#============================================================================================================================================================
;  __CreateVariant
;  __ExtractVariantStrings
;  __GetAdapterNames
;  __GetAdaptersAddresses
;  __IsValidInterface
;  __SafeArrayCreateVector
;  __SafeArrayPutElement
;  __SetVariant
;  __StringArrayToVariantArray
;  __StringToVariant
;  __SysAllocStringLen
;  __SysFreeString
;  __VariantToString
; ================================================================================================================================================================================

; #FUNCTION _NetFw_EnableRuleGroup# ==============================================================================================================================================
; Author.......: Bilgus
; Description..: Enables or disables a specified group of firewall rules
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $sRuleGroup [Literal name of group or Dll String (@ExFWDll.dll, -12345), $bEnabled [True, False]
; Returns......: True on success, False on failure
; ================================================================================================================================================================================

Func _NetFw_EnableRuleGroup($iProfileType, $sRuleGroup, $bEnabled)
    Local $iResult
    $bEnabled = ($bEnabled ? $NET_FW_VARIANT_TRUE : $NET_FW_VARIANT_FALSE)

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.EnableRuleGroup($iProfileType, $sRuleGroup, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($iResult = $S_OK))
EndFunc   ;==>_NetFw_EnableRuleGroup

; #FUNCTION _NetFw_Get_BlockAllInboundTraffic# ===================================================================================================================================
; Author.......: Bilgus
; Description..: Indicates whether the firewall should not allow inbound traffic
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF]
; Returns......: True, False
; ================================================================================================================================================================================

Func _NetFw_Get_BlockAllInboundTraffic($iProfileType)
    Local $iResult, $bEnabled = False

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_BlockAllInboundTraffic($iProfileType, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($bEnabled = True))
EndFunc   ;==>_NetFw_Get_BlockAllInboundTraffic

; #FUNCTION _NetFw_Get_CurrentProfileTypes# ======================================================================================================================================
; Author.......: Bilgus
; Description..: Retrieves the currently active firewall profile(s)
; Parameters...:
; Returns......: $iCurrentProfilesBitMask ($iProfileType) [1|2|4]
; ================================================================================================================================================================================

Func _NetFw_Get_CurrentProfileTypes()
    Local $iResult, $iCurrentProfilesBitMask = 0

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_CurrentProfileTypes($iCurrentProfilesBitMask)
    EndIf

    Return SetError($iResult, Null, $iCurrentProfilesBitMask)
EndFunc   ;==>_NetFw_Get_CurrentProfileTypes

; #FUNCTION _NetFw_Get_DefaultInboundAction# =====================================================================================================================================
; Author.......: Bilgus
; Description..: Indicates the default action for inbound traffic
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF]
; Returns......: $iAction [0, 1, 2], -1 on failure
; ================================================================================================================================================================================

Func _NetFw_Get_DefaultInboundAction($iProfileType)
    Local $iResult, $iAction = -1

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_DefaultInboundAction($iProfileType, $iAction)
    EndIf

    Return SetError($iResult, Null, $iAction)
EndFunc   ;==>_NetFw_Get_DefaultInboundAction

; #FUNCTION _NetFw_Get_DefaultOutboundAction# ====================================================================================================================================
; Author.......: Bilgus
; Description..: Indicates the default action for outbound traffic
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF]
; Returns......:
; ================================================================================================================================================================================

Func _NetFw_Get_DefaultOutboundAction($iProfileType)
    Local $iResult, $iAction = -1

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_DefaultOutboundAction($iProfileType, $iAction)
    EndIf

    Return SetError($iResult, Null, $iAction)
EndFunc   ;==>_NetFw_Get_DefaultOutboundAction

; #FUNCTION _NetFw_Get_ExcludedInterfaces# =======================================================================================================================================
; Author.......: Bilgus
; Description..: Indicates a list of interfaces on which firewall settings are excluded
; .............: Due to a bug in this function the program architecture must match the OS Arch in order to use this function See below for more information
; .............: 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
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $bSupressArchWarning [True, False] Block msgbox error on wrong architecture
; Returns......: $aInterfaces Array of Strings containing friendly name excluded interface, 0 length array on failure or if no excluded interfaces exist
; ================================================================================================================================================================================

Func _NetFw_Get_ExcludedInterfaces($iProfileType, $bSupressArchWarning = False)
    Local Const $MB_ICONERROR = 16
    Local Static $bIsWarned = $bSupressArchWarning
    Local $iResult
    Local $tVariant = __CreateVariant()

    Local $aInterfaces[0]
    If Not @AutoItX64 And @OSArch <> "X86" Then
        If $bIsWarned Then
            ConsoleWriteError("Compiled Architecture must equal OS Architecture in order to use ExcludedInterfaces" & @CRLF)
        Else
            MsgBox($MB_ICONERROR, "INetFwPolicy2 Error", "Compiled Architecture must equal OS Architecture in order to use ExcludedInterfaces")
        EndIf
        $bIsWarned = True
        Return SetError(1, 0, $aInterfaces)
    EndIf

    While __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize)

        $iResult = $__g_oINetFwPolicy2.get_ExcludedInterfaces($iProfileType, DllStructGetPtr($tVariant))
        If $iResult <> $S_OK Then ExitLoop

        If DllStructGetData($tVariant, "vt") <> BitOR($NET_FW_VT_VARIANT, $NET_FW_VT_ARRAY) Then
            $iResult = $E_NOTIMPL
            ExitLoop
        EndIf

        $aInterfaces = __ExtractVariantStrings(DllStructGetPtr($tVariant))

        ExitLoop
    WEnd

    Return SetError($iResult, Null, $aInterfaces)
EndFunc   ;==>_NetFw_Get_ExcludedInterfaces

; #FUNCTION _NetFw_Get_FirewallEnabled# ==========================================================================================================================================
; Author.......: Bilgus
; Description..: Indicates whether a firewall is enabled locally
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF]
; Returns......: True, False
; ================================================================================================================================================================================

Func _NetFw_Get_FirewallEnabled($iProfileType)
    Local $iResult, $bEnabled = False

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_FirewallEnabled($iProfileType, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($bEnabled = True))
EndFunc   ;==>_NetFw_Get_FirewallEnabled

; #FUNCTION _NetFw_Get_IsRuleGroupCurrentlyEnabled# ==============================================================================================================================
; Author.......: Bilgus
; Description..: Determines whether a specified group of firewall rules are enabled or disabled for the current profile
; Parameters...: $sRuleGroup [Literal name of group or Dll String (@ExFWDll.dll, -12345)
; Returns......: True, False
; ================================================================================================================================================================================

Func _NetFw_Get_IsRuleGroupCurrentlyEnabled($sRuleGroup)
    Local $iResult, $bEnabled = False

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_IsRuleGroupCurrentlyEnabled($sRuleGroup, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($bEnabled = True))
EndFunc   ;==>_NetFw_Get_IsRuleGroupCurrentlyEnabled

; #FUNCTION _NetFw_Get_LocalPolicyModifyState# ===================================================================================================================================
; Author.......: Bilgus
; Description..: Determines if adding or setting a rule or group of rules will take effect in the current firewall profile
; Parameters...:
; Returns......: $iModifyState [0, 1, 2], -1 on failure
; ================================================================================================================================================================================

Func _NetFw_Get_LocalPolicyModifyState()
    Local $iResult, $iModifyState = -1

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_LocalPolicyModifyState($iModifyState)
    EndIf

    Return SetError($iResult, Null, $iModifyState)
EndFunc   ;==>_NetFw_Get_LocalPolicyModifyState

; #FUNCTION _NetFw_Get_NotificationsDisabled# ====================================================================================================================================
; Author.......: Bilgus
; Description..: Indicates whether interactive firewall notifications are disabled
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF]
; Returns......: True, False
; ================================================================================================================================================================================

Func _NetFw_Get_NotificationsDisabled($iProfileType)
    Local $iResult, $bEnabled = False

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_NotificationsDisabled($iProfileType, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($bEnabled = True))
EndFunc   ;==>_NetFw_Get_NotificationsDisabled

; #FUNCTION _NetFw_Get_Rules# ====================================================================================================================================================
; Author.......: Bilgus
; Description..: Retrieves the interface to collection of firewall rules
; Parameters...:
; Returns......: Pointer to INetFwRules Object, Null on failure
; ================================================================================================================================================================================

Func _NetFw_Get_Rules()
    Local $iResult
    Local $tINetFwRules = DllStructCreate("ptr pObject")

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_Rules(DllStructGetPtr($tINetFwRules))
    EndIf

    Return SetError($iResult, Null, DllStructGetData($tINetFwRules, "pObject"))
EndFunc   ;==>_NetFw_Get_Rules

; #FUNCTION _NetFw_Get_ServiceRestriction# =======================================================================================================================================
; Author.......: Bilgus
; Description..: Retrieves the interface used to access the Windows Service Hardening store
; Parameters...:
; Returns......: Pointer to INetFwServiceRestriction Object, Null on failure
; ================================================================================================================================================================================

Func _NetFw_Get_ServiceRestriction()
    Local $iResult
    Local $tINetFwServiceRestriction = DllStructCreate("ptr pObject")

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_ServiceRestriction(DllStructGetPtr($tINetFwServiceRestriction))
    EndIf

    Return SetError($iResult, Null, DllStructGetData($tINetFwServiceRestriction, "pObject"))
EndFunc   ;==>_NetFw_Get_ServiceRestriction

; #FUNCTION _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled# =============================================================================================================
; Author.......: Bilgus
; Description..: Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF]
; Returns......: True, False
; ================================================================================================================================================================================

Func _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled($iProfileType)
    Local $iResult, $bEnabled = False

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.get_UnicastResponsesToMulticastBroadcastDisabled($iProfileType, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($bEnabled = True))
EndFunc   ;==>_NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled

; #FUNCTION _NetFw_Initialize# ===================================================================================================================================================
; Author.......: Bilgus
; Description..: Initializes NetFwPolicy2 Interface Returns True if Interface is valid False if not
; .............: Called automatically on first use of a _NetFw_ function
; Parameters...: $bInitialize [True, False - Frees interface]
; Returns......: True, False
; ================================================================================================================================================================================

Func _NetFw_Initialize($bInitialize = True)
    Local $iResult
    If $bInitialize Then
        Local $oObj = ObjCreate("HNetCfg.FwPolicy2")
        Local $sIID = ObjName($oObj, 7) ;Get sIID

        ;Redefine the v-table with our own definitions
        $__g_oINetFwPolicy2 = ObjCreateInterface($oObj, $sIID, $dtag_INetFwPolicy2)
        $iResult = @error
        ;sIID_INetFwPolicy2 = "{98325047-C671-4174-8D81-DEFCD3F03186}"
        ;sCLSID_NetFwPolicy2 = "{E2B3C97F-6AE1-41AC-817A-F6F92166D7DD}"
    Else
        $__g_oINetFwPolicy2 = 0
    EndIf

    If $iResult Or (Not IsObj($__g_oINetFwPolicy2)) Then $bInitialize = False

    Return SetError($iResult, Null, $bInitialize)
EndFunc   ;==>_NetFw_Initialize

; #FUNCTION _NetFw_IsRuleGroupEnabled# ===========================================================================================================================================
; Author.......: Bilgus
; Description..: Determines whether a specified group of firewall rules are enabled or disabled
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $sRuleGroup [Literal name of group or Dll String (@ExFWDll.dll, -12345)
; Returns......: True if enabled False if disabled or doesn't exist
; ================================================================================================================================================================================

Func _NetFw_IsRuleGroupEnabled($iProfileType, $sRuleGroup)
    Local $iResult, $bEnabled = False

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.IsRuleGroupEnabled($iProfileType, $sRuleGroup, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($bEnabled = True))
EndFunc   ;==>_NetFw_IsRuleGroupEnabled

; #FUNCTION _NetFw_Put_BlockAllInboundTraffic# ===================================================================================================================================
; Author.......: Bilgus
; Description..: Specifies whether the firewall should not allow inbound traffic
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $bEnabled [True, False]
; Returns......: True on success False on failure
; ================================================================================================================================================================================

Func _NetFw_Put_BlockAllInboundTraffic($iProfileType, $bEnabled)
    Local $iResult
    $bEnabled = ($bEnabled ? $NET_FW_VARIANT_TRUE : $NET_FW_VARIANT_FALSE)

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.put_BlockAllInboundTraffic($iProfileType, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($iResult = $S_OK))
EndFunc   ;==>_NetFw_Put_BlockAllInboundTraffic

; #FUNCTION _NetFw_Put_DefaultInboundAction# =====================================================================================================================================
; Author.......: Bilgus
; Description..: Specifies the default action for inbound traffic
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $iAction [0, 1, 2]
; Returns......: True on success False on failure
; ================================================================================================================================================================================

Func _NetFw_Put_DefaultInboundAction($iProfileType, $iAction)
    Local $iResult

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.put_DefaultInboundAction($iProfileType, $iAction)
    EndIf

    Return SetError($iResult, Null, ($iResult = $S_OK))
EndFunc   ;==>_NetFw_Put_DefaultInboundAction

; #FUNCTION _NetFw_Put_DefaultOutboundAction# ====================================================================================================================================
; Author.......: Bilgus
; Description..: Specifies the default action for outbound traffic
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $iAction [0, 1, 2]
; Returns......: True on success False on failure
; ================================================================================================================================================================================

Func _NetFw_Put_DefaultOutboundAction($iProfileType, $iAction)
    Local $iResult

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.put_DefaultOutboundAction($iProfileType, $iAction)
    EndIf

    Return SetError($iResult, Null, ($iResult = $S_OK))
EndFunc   ;==>_NetFw_Put_DefaultOutboundAction

; #FUNCTION _NetFw_Put_ExcludedInterfaces# =======================================================================================================================================
; Author.......: Bilgus
; Description..: Specifies a list of interfaces on which firewall settings are excluded
; .............: Due to a bug in this function the program architecture must match the OS Arch in order to use this function See below for more information
; .............: 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
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $aInterfaces [String Array containg names of interfaces to exclude], $bSupressArchWarning [True, False] Block msgbox error on wrong architecture
; Returns......: True on success False on failure
; ================================================================================================================================================================================

Func _NetFw_Put_ExcludedInterfaces($iProfileType, $aInterfaces, $bSupressArchWarning = False)
    Local Const $MB_ICONERROR = 16
    Local Static $bIsWarned = $bSupressArchWarning

    If Not @AutoItX64 And @OSArch <> "X86" Then
        If $bIsWarned Then
            ConsoleWriteError("Compiled Architecture must equal OS Architecture in order to use ExcludedInterfaces" & @CRLF)
        Else
            MsgBox($MB_ICONERROR, "INetFwPolicy2 Error", "Compiled Architecture must equal OS Architecture in order to use ExcludedInterfaces")
        EndIf
        $bIsWarned = True
        Return SetError(1, Null, False)
    EndIf

    Local $iResult
    Local $aNeedsFreed[0] ;Returns variant structs containing Bstr's that need freed
    Local $pSafeArray ;Needed to keep valid reference

    Local $aValidInterfaces[UBound($aInterfaces)]

    ;Remove Invalid Interfaces from list.. ALL Interface names must be valid otherwise the function crashes
    Local $sAdapterNames = __GetAdapterNames()

    Local $j = 0
    For $i = 0 To UBound($aInterfaces) - 1
        If StringInStr($sAdapterNames, $aInterfaces[$i] & ";") > 0 Then
            $aValidInterfaces[$j] = $aInterfaces[$i]
            $j += 1
        EndIf
    Next
    ReDim $aValidInterfaces[$j]

    Local $tVariant = __StringArrayToVariantArray($aValidInterfaces, $pSafeArray, $aNeedsFreed)

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.put_ExcludedInterfaces($iProfileType, DllStructGetPtr($tVariant))
    EndIf

    For $i = 0 To UBound($aNeedsFreed) - 1
        ;Free Bstr's
        __SysFreeString(DllStructGetData($aNeedsFreed[$i], "data"))
    Next

    Return SetError($iResult, Null, ($iResult = $S_OK))
EndFunc   ;==>_NetFw_Put_ExcludedInterfaces

; #FUNCTION _NetFw_Put_FirewallEnabled# ==========================================================================================================================================
; Author.......: Bilgus
; Description..: Specifies whether a firewall is enabled locally (the effective result may differ due to group policy settings)
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $bEnabled [True, False]
; Returns......: True on success False on failure
; ================================================================================================================================================================================

Func _NetFw_Put_FirewallEnabled($iProfileType, $bEnabled)
    Local $iResult
    $bEnabled = ($bEnabled ? $NET_FW_VARIANT_TRUE : $NET_FW_VARIANT_FALSE)

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.put_FirewallEnabled($iProfileType, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($iResult = $S_OK))
EndFunc   ;==>_NetFw_Put_FirewallEnabled

; #FUNCTION _NetFw_Put_NotificationsDisabled# ====================================================================================================================================
; Author.......: Bilgus
; Description..: Specifies whether interactive firewall notifications are disabled
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $bEnabled [True, False]
; Returns......: True on success False on failure
; ================================================================================================================================================================================

Func _NetFw_Put_NotificationsDisabled($iProfileType, $bEnabled)
    Local $iResult
    $bEnabled = ($bEnabled ? $NET_FW_VARIANT_TRUE : $NET_FW_VARIANT_FALSE)

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.put_NotificationsDisabled($iProfileType, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($iResult = $S_OK))
EndFunc   ;==>_NetFw_Put_NotificationsDisabled

; #FUNCTION _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled# =============================================================================================================
; Author.......: Bilgus
; Description..: Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic
; Parameters...: $iProfileType [1,2,4,0x7FFFFFFF], $bEnabled [True, False]
; Returns......: True on success False on failure
; ================================================================================================================================================================================

Func _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled($iProfileType, $bEnabled)
    Local $iResult
    $bEnabled = ($bEnabled ? $NET_FW_VARIANT_TRUE : $NET_FW_VARIANT_FALSE)

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.put_UnicastResponsesToMulticastBroadcastDisabled($iProfileType, $bEnabled)
    EndIf

    Return SetError($iResult, Null, ($iResult = $S_OK))
EndFunc   ;==>_NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled

; #FUNCTION _NetFw_RestoreLocalFirewallDefaults# =================================================================================================================================
; Author.......: Bilgus
; Description..: Restores the local firewall configuration to its default state
; Parameters...:
; Returns......: True on success False on failure
; ================================================================================================================================================================================

Func _NetFw_RestoreLocalFirewallDefaults()
    Local $iResult

    If __IsValidInterface($__g_oINetFwPolicy2, $iResult, _NetFw_Initialize) Then
        $iResult = $__g_oINetFwPolicy2.RestoreLocalFirewallDefaults()
    EndIf

    Return SetError($iResult, Null, ($iResult = $S_OK))
EndFunc   ;==>_NetFw_RestoreLocalFirewallDefaults
#EndRegion Public NetProfile2_Functions

#Region Internal_Functions

; #FUNCTION CreateVariant# =======================================================================================================================================================
; Author.......: Bilgus
; Description..: Creates a Variant sized to the OS architecture 64bit Os Variants are 24 bytes where as X86 uses 16 byte Variants
; Parameters...:
; Returns......: $tVariant (DllStruct Sized Appropriately)
; ================================================================================================================================================================================

Func __CreateVariant()
    Local Const $tagVARIANT_PTR = "word vt;word r1;word r2;word r3;ptr data; ptr"
    ; Thanks @AutoItObject-Team, LarsJ?
    ; The Variant structure takes up 16/24 bytes when running 32/64 bit
    ; Space for the data element at the end represents 2 pointers
    ; This is 8 bytes running 32 bit and 16 bytes running 64 bit

    Local $tVariant = DllStructCreate($tagVARIANT_PTR)

    Return $tVariant
EndFunc   ;==>__CreateVariant

; #FUNCTION ExtractVariantStrings# ===============================================================================================================================================
; Author.......: Bilgus
; Description..: Extracts Strings from Passed Variant Array and places them into an Autoit Array
; Parameters...: $pVariant (Pointer to a Variant)
; Returns......: Array containg each string on success Empty array on failure or if no strings were contained
; ================================================================================================================================================================================

Func __ExtractVariantStrings($pVariant, $sSeparator = "; ")
    Local Const $STR_ENTIRESPLIT = 1, $STR_NOCOUNT = 2
    Local $aEmpty[0]

    If Not $pVariant Then Return SetError(1, 0, $aEmpty)

    Local $sStrings = __VariantToString($pVariant)

    Return SetError(@error, Null, StringSplit($sStrings, $sSeparator, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT)))
EndFunc   ;==>__ExtractVariantStrings

; #FUNCTION GetAdapterNames# =====================================================================================================================================================
; Author.......: Bilgus
; Description..: Uses GetAdaptersAddresses to retrieve a string of adapter FriendlyNames on the computer each name is separated by $sSeparator
; Parameters...: $sSeparator = ";"
; Returns......: String containg adaptor FriendlyNames on success Empty String on failure
; ================================================================================================================================================================================

Func __GetAdapterNames($sSeparator = ";")
    Local Enum Step *2 $GAA_FLAG_SKIP_UNICAST = 0x1, $GAA_FLAG_SKIP_ANYCAST, $GAA_FLAG_SKIP_MULTICAST, $GAA_FLAG_SKIP_DNS_SERVER
    Local $iFlags = BitOR($GAA_FLAG_SKIP_UNICAST, $GAA_FLAG_SKIP_ANYCAST, $GAA_FLAG_SKIP_MULTICAST, $GAA_FLAG_SKIP_DNS_SERVER)

    Local Const $tagIP_ADAPTER_FRIENDLYNAME = "ulong;dword;ptr Next;ptr;ptr;ptr;ptr;ptr;ptr;ptr; ptr FriendlyName;"
    Local $tIP_ADAPTER_FRIENDLYNAME, $sAdapterNames = ""

    Local $tBuf_AdapterAddresses = __GetAdaptersAddresses(0, $iFlags)
    Local $iError = @error

    While Not $iError
        Local $pBuf_AdapterAddress = DllStructGetPtr($tBuf_AdapterAddresses)

        While $pBuf_AdapterAddress
            $tIP_ADAPTER_FRIENDLYNAME = DllStructCreate($tagIP_ADAPTER_FRIENDLYNAME, $pBuf_AdapterAddress)
            $sAdapterNames &= _WinAPI_GetString(DllStructGetData($tIP_ADAPTER_FRIENDLYNAME, "FriendlyName")) & $sSeparator
            $iError = @error
            If $iError Then ExitLoop
            $pBuf_AdapterAddress = DllStructGetData($tIP_ADAPTER_FRIENDLYNAME, "Next")
        WEnd
        ExitLoop
    WEnd

    Return SetError($iError, Null, $sAdapterNames)
EndFunc   ;==>__GetAdapterNames

; #FUNCTION GetAdaptersAddresses# ================================================================================================================================================
; Author.......: Bilgus
; Description..: Retrieves the addresses associated with the adapters on the local computer
; Parameters...: $iFamily = 0 [0,2,23], $iFlags = 0 [0x0, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400]
; Returns......: $tBuf_AdapterAddresses[DllStruct Buffer for further processing of data], Empty variable on Failure
; ================================================================================================================================================================================

Func __GetAdaptersAddresses($iFamily = 0, $iFlags = 0)
    Local Const $ERROR_BUFFER_OVERFLOW = 0x6F
    Local $iError = $ERROR_BUFFER_OVERFLOW
    Local $iSzBuffer = 16000 ;Initial Buffer
    Local $iRetries = 3
    Local $aRet, $tBuf_AdapterAddresses
    Local $hIphlpapi = DllOpen("Iphlpapi.dll")
    While $iRetries > 0
        If Not $hIphlpapi Then
            $iError = $NET_FW_UNKNOWNERROR
            ExitLoop
        EndIf

        While $iError = $ERROR_BUFFER_OVERFLOW And $iRetries > 0
            $iRetries -= 1
            $tBuf_AdapterAddresses = DllStructCreate("byte[" & $iSzBuffer & "]")

            $aRet = DllCall($hIphlpapi, "ulong", "GetAdaptersAddresses", _
                    "ulong", $iFamily, _
                    "ulong", $iFlags, _
                    "ptr", Null, _
                    "ptr", DllStructGetPtr($tBuf_AdapterAddresses), _
                    "dword*", $iSzBuffer)

            If Not @error And IsArray($aRet) Then
                $iError = $aRet[0]
                If $aRet[0] = $ERROR_BUFFER_OVERFLOW Then
                    If $iSzBuffer <= DllStructGetSize($tBuf_AdapterAddresses) Then ExitLoop
                    ContinueLoop
                EndIf
            Else
                $iError = @error
            EndIf

            ExitLoop
        WEnd
        ExitLoop
    WEnd

    DllClose($hIphlpapi)
    Return SetError($iError, Null, $tBuf_AdapterAddresses)
EndFunc   ;==>__GetAdaptersAddresses

; #FUNCTION IsValidInterface# ====================================================================================================================================================
; Author.......: Bilgus
; Description..: Checks if passed Object Variable is an Object
; Parameters...: $oInterface[Object], ByRef $iResult, $fInit[function that attempts to (re) initialize object
; Returns......: True if $oInterface is an object, False on failure and iResult is set to $E_NOINTERFACE
; ================================================================================================================================================================================

Func __IsValidInterface(ByRef $oInterface, ByRef $iResult, $fInit = 0)
    If Not IsObj($oInterface) And $fInit <> 0 Then Call($fInit)
    If @error = 0xDEAD Then ConsoleWriteError("Invalid Init Function" & @CRLF)

    If Not IsObj($oInterface) Then
        ConsoleWriteError("Failed To Retrieve Interface" & @CRLF)
        $iResult = $E_NOINTERFACE
        Return SetError($iResult, Null, False)
    EndIf

    Return True
EndFunc   ;==>__IsValidInterface

; #FUNCTION SafeArrayCreateVector# ===============================================================================================================================================
; Author.......: Bilgus
; Description..: Creates a fixed size one-dimensional array
; Parameters...: $iVType[ushort VARTYPE (VT_EMPTY and VT_NULL are not allowed)], $iElements[Integer Number of elements to create], $iLBound = 0[Integer Lower bound of array]
; Returns......: Pointer to SafeArray on success Null on failure
; ================================================================================================================================================================================

Func __SafeArrayCreateVector($iVType, $iElements, $iLBound = 0, $vDll = "OleAut32.dll")
    Local $iError
    Local $aRet = DllCall($vDll, "ptr", "SafeArrayCreateVector", "ushort", $iVType, "long", $iLBound, "ulong", $iElements)

    If Not @error And IsArray($aRet) Then
        If $aRet[0] <> Null Then
            Return $aRet[0]
        EndIf
        $iError = $NET_FW_UNKNOWNERROR
    Else
        $iError = @error
    EndIf

    Return SetError($iError, Null, Null)
EndFunc   ;==>__SafeArrayCreateVector

; #FUNCTION SafeArrayPutElement# =================================================================================================================================================
; Author.......: Bilgus
; Description..: Stores $pdata at the specified element location in the array
; Parameters...: $pSafeArray[Pointer to SafeArray], $iIndex[Integer element to place data], $pData[Pointer to data to be inserted]
; Returns......: True on success False on error
; ================================================================================================================================================================================

Func __SafeArrayPutElement($pSafeArray, $iIndex, $pData, $vDll = "OleAut32.dll")
    Local $iError
    Local $aRet = DllCall($vDll, "long", "SafeArrayPutElement", "ptr", $pSafeArray, "long*", $iIndex, "ptr", $pData)

    If Not @error And IsArray($aRet) Then
        $iError = $aRet[0]
    Else
        $iError = @error
    EndIf

    Return SetError($iError, Null, ($iError = $S_OK))
EndFunc   ;==>__SafeArrayPutElement

; #FUNCTION SetVariant# ==========================================================================================================================================================
; Author.......: Bilgus
; Description..: Stores $iVarType and $pData at the specified element location in the variant
; Parameters...: $tVariant[DllStruct Variant], $VarType[The VT_* Constant], $pData[Pointer to data to be inserted]
; Returns......: True on success False on error
; ================================================================================================================================================================================

Func __SetVariant(ByRef $tVariant, $iVarType, $pData)

    Local $iError
    If IsDllStruct($tVariant) Then
        If Not DllStructSetData($tVariant, "vt", $iVarType) Then $iError = BitOR($iError, 1)
        If Not DllStructSetData($tVariant, "data", $pData) Then $iError = BitOR($iError, 2)
    Else
        $iError = 3
    EndIf

    Return SetError($iError, Null, ($iError = 0))
EndFunc   ;==>__SetVariant

; #FUNCTION StringArrayToVariantArray# ===========================================================================================================================================
; Author.......: Bilgus
; Description..: Copies an array of AutoIt strings into a variant array each string is Converted to a BSTR and Placed in a separate Variant
; .............: Top Level Variant is of type (VT_VARIANT|VT_ARRAY) each sub Variant is type (VT_BSTR) and contains an individual BSTR
;..............: $aNeedsFreed holds the sub level variants, The BSTRs within each needs freed when you are finished using them
;..............: $pSafeArray should be passed in as an empty variable to hold a reference to the SafeArray data
;..............: $aNeedsFreed should be an empty array in the form of $aNeedsFreed[0] the function will redim it as necessary
;..............: $tVariant will be a completely empty variant if there are no strings passed within $aArrStrings
; Parameters...: $aArrStrings, ByRef $pSafeArray[EMPTY VARIABLE], ByRef $aNeedsFreed[0]{0 dim array}
; Returns......: $tVariant (DllStruct Containg the Passed Strings)
; ================================================================================================================================================================================

Func __StringArrayToVariantArray($aArrStrings, ByRef $pSafeArray, ByRef $aNeedsFreed)
    ;NOTE!, You Need To Free pBstr's When you are finished with them
    ;$aNeedsFreed Returns variants containg the Bstr's
    Local $iError
    Local $tVariant = __CreateVariant()
    Local $iCtStrings = UBound($aArrStrings)
    ReDim $aNeedsFreed[$iCtStrings]
    While $iCtStrings > 0 ;If The array is empty we want to return empty variant
        $pSafeArray = __SafeArrayCreateVector($NET_FW_VT_VARIANT, $iCtStrings)
        $iError = @error
        If $iError Then ExitLoop

        For $i = 0 To $iCtStrings - 1
            $aNeedsFreed[$i] = __CreateVariant();Create a sub Variant to hold the BSTR

            __StringToVariant($aArrStrings[$i], $aNeedsFreed[$i])
            $iError = @error
            If $iError Then ExitLoop

            __SafeArrayPutElement($pSafeArray, $i, DllStructGetPtr($aNeedsFreed[$i]))
            $iError = @error
            If $iError Then ExitLoop
        Next

        If Not $iError Then
            __SetVariant($tVariant, BitOR($NET_FW_VT_VARIANT, $NET_FW_VT_ARRAY), $pSafeArray)
            $iError = @error
        EndIf

        ExitLoop
    WEnd
    Return SetError($iError, Null, $tVariant)
EndFunc   ;==>__StringArrayToVariantArray

; #FUNCTION StringToVariant# =====================================================================================================================================================
; Author.......: Bilgus
; Description..: Copies an AutoIt string into an allocated BSTR Which is placed into a Variant with type VT_BSTR
; Parameters...: $sString, ByRef $tVariant (Variant DllStruct)
; Returns......: True on Success False on Failure
; ================================================================================================================================================================================

Func __StringToVariant($sString, ByRef $tVariant)
    ;NOTE!, YOU Need To Free pBstr When you are finished with it ;__SysFreeString($pBstr)
    Local $pBstr = __SysAllocStringLen($sString)
    Local $iError = @error

    If Not $iError And $pBstr Then
        __SetVariant($tVariant, $NET_FW_VT_BSTR, $pBstr)
        $iError = @error
    Else
        __SetVariant($tVariant, 0, 0)
        $iError = BitOR(@error, $iError)
    EndIf

    Return SetError($iError, Null, ($iError = 0))
EndFunc   ;==>__StringToVariant

; #FUNCTION SysAllocStringLen# ======================================================================================================================================================
; Author.......: Bilgus
; Description..: Allocates a new BSTR and copies the passed AutoIt string into it.
; Parameters...: $sString
; Returns......: NULL on error otherwise pointer to system allocated BSTR
; ================================================================================================================================================================================

Func __SysAllocStringLen($sString, $vDll = "OleAut32.dll")
    ;NOTE!, YOU Need To Free pBstr When you are finished with it ;__SysFreeString($pBstr)
    Local $iError

    Local $aRet = DllCall($vDll, "ptr", "SysAllocStringLen", "wstr", $sString, "uint", StringLen($sString))

    If Not @error And IsArray($aRet) Then
        If $aRet[0] <> Null Then
            Return $aRet[0]
        Else
            $iError = $NET_FW_UNKNOWNERROR
        EndIf
    Else
        $iError = @error
    EndIf

    Return SetError($iError, Null, Null)
EndFunc   ;==>__SysAllocStringLen

; #FUNCTION SysFreeString# =======================================================================================================================================================
; Author.......: Bilgus
; Description..: Frees a SysAllocString
; Parameters...: $pBstr (Pointer to a BSTR)
; Returns......: None
; ================================================================================================================================================================================

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

; #FUNCTION VariantToString# =====================================================================================================================================================
; Author.......: Bilgus
; Description..: Converts VT_BSTR to an AutoIt string
; Parameters...: $pVariant (Pointer to a Variant)
; Returns......: String Contained in passed Variant
; ================================================================================================================================================================================

Func __VariantToString($pVariant, $vDll = "Propsys.dll")
    Local $iError
    Local $aRet = DllCall($vDll, "long", "VariantToString", "ptr", $pVariant, "wstr", "", "uint", 65535)

    If Not @error And IsArray($aRet) Then
        If $aRet[0] = $S_OK Then
            Return $aRet[2]
        Else
            $iError = $aRet[0]
        EndIf
    Else
        $iError = @error
    EndIf

    Return SetError($iError, Null, "")
EndFunc   ;==>__VariantToString
#EndRegion Internal_Functions

 

Test Script:

Spoiler
;Test Script For INetFWPolicy2
#RequireAdmin

#include <INetFwPolicy2COM.au3>
#include <GUIConstantsEx.au3>

Global $sOutputAccumulated

;_NetFw_Initialize(True) ;Initialize interface done automatic on first use of a function

Test_Get_CurrentProfileTypes()
Test_Get_LocalPolicyModifyState()
Test_FirewallEnabled()
Test_ExcludedInterfaces()
Test_Rules()
Test_ServiceRestriction()
Test_RuleGroupEnabled()
Test_DefaultAction()

_NetFw_Initialize(False) ;Un-Initialize (Frees) Interface

$sOutputAccumulated &= "Done!" & @CRLF

Global $hGUI = GUICreate("INetFWPolicy2", 600, 400)
Global $idEdit = GUICtrlCreateEdit($sOutputAccumulated, 5, 5, 590, 390)

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idOK
            ExitLoop

    EndSwitch
WEnd

; Delete the GUI and all controls.
GUIDelete($hGUI)
Exit

Func Test_DefaultAction()
    WriteOutput("Default Inbound/Outbound Actions:" & @CRLF)
    Local $DefaultOutbound = _NetFw_Get_DefaultOutboundAction($NET_FW_PROFILE2_PRIVATE)
    Local $DefaultInbound = _NetFw_Get_DefaultInboundAction($NET_FW_PROFILE2_PRIVATE)
    WriteOutput("Private Outbound: " & DefaultActionToString($DefaultOutbound) & @CRLF)
    WriteOutput("Private Inbound: " & DefaultActionToString($DefaultInbound) & @CRLF)

    _NetFw_Put_DefaultOutboundAction($NET_FW_PROFILE2_PRIVATE, $NET_FW_ACTION_BLOCK)
    _NetFw_Put_DefaultInboundAction($NET_FW_PROFILE2_PRIVATE, $NET_FW_ACTION_BLOCK)
    WriteOutput("Private Outbound: " & DefaultActionToString(_NetFw_Get_DefaultOutboundAction($NET_FW_PROFILE2_PRIVATE)) & @CRLF)
    WriteOutput("Private Inbound: " & DefaultActionToString(_NetFw_Get_DefaultInboundAction($NET_FW_PROFILE2_PRIVATE)) & @CRLF)

    _NetFw_Put_DefaultOutboundAction($NET_FW_PROFILE2_PRIVATE, $NET_FW_ACTION_ALLOW)
    _NetFw_Put_DefaultInboundAction($NET_FW_PROFILE2_PRIVATE, $NET_FW_ACTION_ALLOW)
    WriteOutput("Private Outbound: " & DefaultActionToString(_NetFw_Get_DefaultOutboundAction($NET_FW_PROFILE2_PRIVATE)) & @CRLF)
    WriteOutput("Private Inbound: " & DefaultActionToString(_NetFw_Get_DefaultInboundAction($NET_FW_PROFILE2_PRIVATE)) & @CRLF)

    _NetFw_Put_DefaultOutboundAction($NET_FW_PROFILE2_PRIVATE, $NET_FW_ACTION_MAX)
    _NetFw_Put_DefaultInboundAction($NET_FW_PROFILE2_PRIVATE, $NET_FW_ACTION_MAX)
    WriteOutput("Private Outbound: " & DefaultActionToString(_NetFw_Get_DefaultOutboundAction($NET_FW_PROFILE2_PRIVATE)) & @CRLF)
    WriteOutput("Private Inbound: " & DefaultActionToString(_NetFw_Get_DefaultInboundAction($NET_FW_PROFILE2_PRIVATE)) & @CRLF)

    WriteOutput(@CRLF & "Restoring..." & @CRLF)
    _NetFw_Put_DefaultOutboundAction($NET_FW_PROFILE2_PRIVATE, $DefaultOutbound)
    _NetFw_Put_DefaultInboundAction($NET_FW_PROFILE2_PRIVATE, $DefaultInbound)
    WriteOutput("Private Outbound: " & DefaultActionToString(_NetFw_Get_DefaultOutboundAction($NET_FW_PROFILE2_PRIVATE)) & @CRLF)
    WriteOutput("Private Inbound: " & DefaultActionToString(_NetFw_Get_DefaultInboundAction($NET_FW_PROFILE2_PRIVATE)) & @CRLF & @CRLF)
EndFunc   ;==>Test_DefaultAction

Func Test_ExcludedInterfaces()
    WriteOutput("get Excluded Interfaces:" & @CRLF)

    WriteOutput("Domain: " & @CRLF & PrintArray(_NetFw_Get_ExcludedInterfaces($NET_FW_PROFILE2_DOMAIN)) & @CRLF)

    Local $aPrivateExcluded = _NetFw_Get_ExcludedInterfaces($NET_FW_PROFILE2_PRIVATE) ; For restoration..
    WriteOutput("Private: " & @CRLF & PrintArray($aPrivateExcluded) & @CRLF)

    WriteOutput("Public: " & @CRLF & PrintArray(_NetFw_Get_ExcludedInterfaces($NET_FW_PROFILE2_PUBLIC)) & @CRLF)

    WriteOutput(@CRLF)
    WriteOutput("Put Excluded Interfaces:" & @CRLF)

    Local $aInterfaces[4] = ["Wireless Network Connection", "Wireless Network Connection 2", "Local Area Connection", "Local Area Connection 2"]
    _NetFw_Put_ExcludedInterfaces($NET_FW_PROFILE2_PRIVATE, $aInterfaces)

    WriteOutput("Private: " & @CRLF & PrintArray(_NetFw_Get_ExcludedInterfaces($NET_FW_PROFILE2_PRIVATE)) & @CRLF)

    WriteOutput(@CRLF & "Restoring..." & @CRLF)
    _NetFw_Put_ExcludedInterfaces($NET_FW_PROFILE2_PRIVATE, $aPrivateExcluded)

    WriteOutput("Private: " & @CRLF & PrintArray(_NetFw_Get_ExcludedInterfaces($NET_FW_PROFILE2_PRIVATE)) & @CRLF)

EndFunc   ;==>Test_ExcludedInterfaces

Func Test_FirewallEnabled()
    WriteOutput("Firewall Enabled:" & @CRLF)
    Toggle_FirewallEnabled($NET_FW_PROFILE2_DOMAIN)
    Toggle_FirewallEnabled($NET_FW_PROFILE2_PUBLIC)
    Toggle_FirewallEnabled($NET_FW_PROFILE2_PRIVATE)
EndFunc   ;==>Test_FirewallEnabled

Func Test_Get_CurrentProfileTypes()
    Local $iCurrentProfilesBitMask = _NetFw_Get_CurrentProfileTypes()
    Local $sProfiles = "CurrentProfiles: " & ProfileTypeToString($iCurrentProfilesBitMask)
    WriteOutput($sProfiles & @CRLF & @CRLF)
EndFunc   ;==>Test_Get_CurrentProfileTypes

Func Test_Get_LocalPolicyModifyState()
    Local $iModifyState = _NetFw_Get_LocalPolicyModifyState()
    WriteOutput("Policy Modify State: " & ModifyStateToString($iModifyState) & @CRLF & @CRLF)
EndFunc   ;==>Test_Get_LocalPolicyModifyState

Func Test_RuleGroupEnabled()
    WriteOutput("Rule Group Enabled:" & @CRLF)
    Local $bEnabled = _NetFw_Get_IsRuleGroupCurrentlyEnabled("Remote Assistance")
    WriteOutput("Remote Assistance Current Profile: " & ($bEnabled ? "True" : "False") & @CRLF & @CRLF)

    $bEnabled = _NetFw_IsRuleGroupEnabled($NET_FW_PROFILE2_PRIVATE, "Remote Assistance")
    WriteOutput("Remote Assistance: " & ($bEnabled ? "True" : "False") & @CRLF)
    _NetFw_EnableRuleGroup($NET_FW_PROFILE2_PRIVATE, "Remote Assistance", Not $bEnabled)

    $bEnabled = _NetFw_Get_IsRuleGroupCurrentlyEnabled("Remote Assistance")
    WriteOutput("Remote Assistance Current Profile: " & ($bEnabled ? "True" : "False") & @CRLF & @CRLF)

    $bEnabled = _NetFw_IsRuleGroupEnabled($NET_FW_PROFILE2_PRIVATE, "Remote Assistance")
    WriteOutput("Remote Assistance: " & ($bEnabled ? "True" : "False") & @CRLF)
    _NetFw_EnableRuleGroup($NET_FW_PROFILE2_PRIVATE, "Remote Assistance", Not $bEnabled)

    WriteOutput(@CRLF & "Restoring..." & @CRLF)
    $bEnabled = _NetFw_IsRuleGroupEnabled($NET_FW_PROFILE2_PRIVATE, "Remote Assistance")
    WriteOutput("Remote Assistance: " & ($bEnabled ? "True" : "False") & @CRLF & @CRLF)

EndFunc   ;==>Test_RuleGroupEnabled

Func Test_Rules()
    WriteOutput("Pointer INetFwRule = " & Hex(_NetFw_Get_Rules()) & @CRLF & @CRLF)
EndFunc   ;==>Test_Rules

Func Test_ServiceRestriction()
    WriteOutput("Pointer INetFwServiceRestriction = " & Hex(_NetFw_Get_ServiceRestriction()) & @CRLF & @CRLF)
EndFunc   ;==>Test_ServiceRestriction

Func DefaultActionToString($iAction)
    Local $sAction
    Switch $iAction
        Case $NET_FW_ACTION_BLOCK
            $sAction = "Block"
        Case $NET_FW_ACTION_ALLOW
            $sAction = "Allow"
        Case $NET_FW_ACTION_MAX
            $sAction = "Max"
        Case Else
            $sAction = "Error"
    EndSwitch
    Return $sAction
EndFunc   ;==>DefaultActionToString

Func ModifyStateToString($iModifyState)
    Local $sModifyState
    Switch $iModifyState
        Case $NET_FW_MODIFY_STATE_OK
            $sModifyState = "OK"
        Case $NET_FW_MODIFY_STATE_GP_OVERRIDE
            $sModifyState = "Group Policy Override"
        Case $NET_FW_MODIFY_STATE_INBOUND_BLOCKED
            $sModifyState = "Inbound Blocked"
        Case Else
            $sModifyState = "Error"
    EndSwitch
    Return $sModifyState
EndFunc   ;==>ModifyStateToString

Func PrintArray($aArr)
    $sRet = ""
    If IsArray($aArr) Then
        For $i = 0 To UBound($aArr) - 1
            $sRet &= $aArr[$i] & @CRLF
        Next
    EndIf
    Return $sRet
EndFunc   ;==>PrintArray

Func ProfileTypeToString($iProfileType)
    Local $sProfiles
    $sProfiles &= (BitAND($iProfileType, $NET_FW_PROFILE2_DOMAIN) ? "Domain" : "")
    $sProfiles &= (BitAND($iProfileType, $NET_FW_PROFILE2_PRIVATE) ? "Private" : "")
    $sProfiles &= (BitAND($iProfileType, $NET_FW_PROFILE2_PUBLIC) ? "Public" : "")
    $sProfiles &= (BitAND($iProfileType, $NET_FW_PROFILE2_ALL) = $NET_FW_PROFILE2_ALL ? "All " : "")
    If $sProfiles = "" Then $sProfiles = "FAILED "
    Return $sProfiles
EndFunc   ;==>ProfileTypeToString

Func Toggle_FirewallEnabled($iProfileType)
    Local Const $sFw = "Firewall Profile "
    Local $bEnabled = _NetFw_Get_FirewallEnabled($iProfileType)
    If Not @error Then WriteOutput($sFw & ProfileTypeToString($iProfileType) & ($bEnabled ? " Enabled" : " Disabled") & @CRLF)

    _NetFw_Put_FirewallEnabled($iProfileType, Not $bEnabled)

    $bEnabled = _NetFw_Get_FirewallEnabled($iProfileType)
    If Not @error Then WriteOutput($sFw & ProfileTypeToString($iProfileType) & ($bEnabled ? " Enabled" : " Disabled") & @CRLF)

    WriteOutput(@CRLF & "Restoring..." & @CRLF)
    _NetFw_Put_FirewallEnabled($iProfileType, Not $bEnabled)

    $bEnabled = _NetFw_Get_FirewallEnabled($iProfileType)
    If Not @error Then WriteOutput($sFw & ProfileTypeToString($iProfileType) & ($bEnabled ? " Enabled" : " Disabled") & @CRLF & @CRLF)
EndFunc   ;==>Toggle_FirewallEnabled

Func WriteOutput($sOutput)

    $sOutputAccumulated &= $sOutput
    ConsoleWrite($sOutput)

EndFunc   ;==>WriteOutput

 

 

Edited by Bilgus
UDF wasn't posted
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Bilgus
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
mLipok

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post


Link to post
Share on other sites
water
Posted (edited)

Will do :) 

Edit: Done

Edited by water
  • Thanks 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • Bilgus
      By Bilgus
      I was Playing around With AutoIt this evening and wondered how hard it would be to get typeinfo like the COM Viewers do only using AutoIt
      Turns out it was pretty easy.
      A Few Notes:
      CAarray info is unfinished I didn't have any objects to test it on so I left it Limited.
      The Object must have IDispatch exposed (ITypeInfo is derivative)
      Its Just a proof of concept Run with it but don't carry scissors
      ITypeInfoCOM.au3
      ITypeInfoTest.au3
       
      Output IWebBrowserApp
       
      Output ObjCreate(MediaPlayer.MediaPlayer.1)
       
    • Bilgus
      By Bilgus
       IGroupPolicyObject interface
      ;;IGroupPolicyObject #RequireAdmin #include-once #include <WinAPIConstants.au3> ; $S_OK #include <WinAPIReg.au3> ;_WinAPI_GetRegKeyNameByHandle Global Enum $GPO_SECTION_ROOT = 0x0, $GPO_SECTION_USER, $GPO_SECTION_MACHINE Global Enum $GPO_OPEN_LOAD_REGISTRY = 0x1, $GPO_OPEN_READ_ONLY Global Enum $GPO_OPTION_DISABLE_USER = 0x1, $GPO_OPTION_DISABLE_MACHINE Global Enum $GPOTypeLocal = 0x0, $GPOTypeRemote, $GPOTypeDS, $GPOTypeLocalUser, $GPOTypeLocalGroup Global Const $sCLSID_GroupPolicyObject = "{EA502722-A23D-11D1-A7D3-0000F87571E3}" Global Const $sIID_IGroupPolicyObject = "{EA502723-A23D-11D1-A7D3-0000F87571E3}" Global Const $dtag_IGroupPolicyObject = _ "New hresult(wstr;wstr;dword);" & _ ; Creates a new GPO in the Active Directory with the specified display name. "OpenDSGPO hresult(wstr;dword);" & _ ; Opens the specified GPO and optionally loads the registry information. "OpenLocalMachineGPO hresult(dword);" & _ ; Opens the default GPO for the computer and optionally loads the registry information. "OpenRemoteMachineGPO hresult(wstr;dword);" & _ ; Opens the default GPO for the specified remote computer and optionally loads the registry information. "Save hResult(bool;bool;ptr;ptr);" & _ ; Saves the specified registry policy settings to disk and updates the revision number of the GPO. "Delete hresult();" & _ ; Deletes the GPO. "GetName hResult(wstr;int);" & _ ; Retrieves the unique name for the GPO. "GetDisplayName hResult(wstr;int);" & _ ; Retrieves the display name for the GPO. "SetDisplayName hresult(wstr);" & _ ; Sets the display name for the GPO. "GetPath hResult(wstr;int);" & _ ; Retrieves the path to the GPO. "GetDSPath hresult(dword;wstr;int);" & _ ; Retrieves the Active Directory path to the root of the specified GPO section. "GetFileSysPath hresult(dword;wstr;int);" & _ ; Retrieves the file system path (UNC format) to the root of the specified GPO section. "GetRegistryKey hresult(dword;handle);" & _ ; Retrieves a handle to the root of the registry key for the specified GPO section. "GetOptions hResult(dword*);" & _ ; Retrieves the options for the GPO. "SetOptions hresult(dword;dword);" & _ ; Sets the options for the GPO. "GetType hResult(dword*);" & _ ; Retrieves type information for the GPO being edited. "GetMachineName hResult(wstr;int);" & _ ; Retrieves the computer name of the remote GPO. "GetPropertySheetPages hresult(ptr;uint*);" ; Retrieves the property sheet pages associated with the GPO. Test() Func Test() Local $iResult Local $oIGroupPolicy Local $aGpoType[5] = ["Local", "Remote", "Active Directory", "LocalUser", "LocalGroup"] $oIGroupPolicy = ObjCreateInterface($sCLSID_GroupPolicyObject, $sIID_IGroupPolicyObject, $dtag_IGroupPolicyObject) While True If Not IsObj($oIGroupPolicy) Then ConsoleWrite("Failed To Retrieve Interface") $iResult = $E_NOINTERFACE ExitLoop Else ConsoleWrite("Success: " & ObjName($oIGroupPolicy, 1) & @CRLF) EndIf Local $sLoc, $sPath, $sName, $iType $tKey = DllStructCreate("handle hKey") $iResult = $oIGroupPolicy.OpenLocalMachineGPO(BitOR($GPO_OPEN_LOAD_REGISTRY, $GPO_OPEN_READ_ONLY)) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetDisplayName($sLoc, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetName($sName, 65535) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sLoc & " : " & $sName & @CRLF) $iResult = $oIGroupPolicy.GetPath($sPath, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sPath & @CRLF) $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite("Type: " & $aGpoType[$iType] & @CRLF) $iResult = $oIGroupPolicy.GetRegistryKey($GPO_SECTION_USER, DllStructGetPtr($tKey)) If $iResult <> $S_OK Then ExitLoop ConsoleWrite(_WinAPI_GetRegKeyNameByHandle(DllStructGetData($tKey, "hKey")) & @CRLF) ExitLoop WEnd Return SetError($iResult, 0, ($iResult = $S_OK)) EndFunc ;==>Test Note: Not well tested..
    • Fenzik
      By Fenzik
       Hello all"
      I have curious problem with com object implementation of Sapi 5.1.
      In some cases }Some Voice engines] the metods for retrieve the voice parameters fails with error :Member not exists:.
      But the Retrieved Voice object can speak the given text, so It exists and work.
      Example of this type of Engine can be this one: http://download.kobavision.be/KobaSpeech3/KobaSpeech 3 With Vocalizer Serena - English (Great Britain).exe (can work as demo)
      So my question is> Is there some way to workaround or solve this issue?
      What i tryed:
      1. Typical use of Sapi.spvoice object:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
       
        $spvoice = ObjCreate("sapi.spvoice")
      for $voice in $spvoice.getvoices()
        msgbox(0, "Voice", $voice.getdescription())
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc

      2. Implement workaround based on Nvda Screen reader sapi5 Library at https://github.com/nvaccess/nvda/blob/master/source/synthDrivers/sapi5.py
      Thys code in Pascal should work, so i tryed to reproduce it in Autoit.
      Pascal code just as example:
                   SOTokens:=SpVoice.GetVoices('','');
                   for i:=0 to SOTokens.Count-1 do
                   try
                        SOToken:=SOTokens.Item(I); s:=SOToken.GetDescription(0);
      end
      In Autoit I tryed it like this:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
        $spvoice = ObjCreate("sapi.spvoice")
      for $i = 0 to $spvoice.getvoices.count-1
      $name = $spvoice.getvoices.item($i).getdescription
      msgbox(0,"Voice", $name)
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc
      Both of this methods returning same Error ("Member not exists.").
      Thanks a lot for help.
      Znefyg
    • gillesg
      By gillesg
      Hello,
       
      Is there a way to get all the properties and method of a COM object thru Autoit.
      I am looking in a way of display the imbricated structure of object and method.
       
      Example of COm objects are "itunes.application", "Shell.application" and so on.
      The idea is to have a code looking like
      $objtobrowse = objcreate("itunes.application") if isobj($objtobrowse) then $colItems = $objtobrowse.buildinproperty For $objItem In $colItems ConsoleWrite($objItem.<Name> & " - " & $objItem.<Value> & @CRLF) Next EndIf  
    • timmalos
      By timmalos
      Hey all.
      I'm a little stuck starting with COM interfacing with Microsoft OneNote.
      The msdn doc is there : https://msdn.microsoft.com/en-us/library/office/jj680118.aspx?f=255&MSPPError=-2147217396
      I found, with the OleViewer what I need to access :
      // Generated .IDL file (by the OLE/COM Object Viewer) // // typelib filename: 3 [ uuid(0EA692EE-BB50-4E3C-AEF0-356D91732725), version(1.1), helpstring("Microsoft OneNote 15.0 Object Library"), custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 134218339), custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 2147483647), custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, Created by MIDL version 8.00.0611 at Mon Jan 18 19:14:07 2038 ), custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Microsoft.Office.Interop.OneNote.dll) ] library OneNote { // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} importlib("stdole2.tlb"); // Forward declare all types defined in this typelib interface IQuickFilingDialog; interface IQuickFilingDialogCallback; interface IApplication; interface Windows; interface Window; dispinterface IOneNoteEvents; typedef [uuid(552E0E02-B287-4EC6-9CC0-4BA019EE5EA1)] enum { hsSelf = 0, hsChildren = 1, hsNotebooks = 2, hsSections = 3, hsPages = 4 } HierarchyScope; typedef [uuid(41C8F6EA-0AF0-4A4F-99E9-5EB01EBFC9A3)] enum { heNone = 0, heNotebooks = 1, heSectionGroups = 2, heSections = 4, hePages = 8 } HierarchyElement; typedef [uuid(4DB67B4F-CC7D-45B5-88FE-569AE5798FF2)] enum { rrtNone = 0, rrtFiling = 1, rrtSearch = 2, rrtLinks = 3 } RecentResultType; typedef [uuid(B5EB9D34-5278-4D8A-AE1F-2F88EA56BBCE)] enum { cftNone = 0, cftNotebook = 1, cftFolder = 2, cftSection = 3 } CreateFileType; typedef [uuid(D6E78E55-7EE7-4A31-BF3E-B01E819599BA)] enum { piBasic = 0, piBinaryData = 1, piSelection = 2, piFileType = 4, piBinaryDataSelection = 3, piBinaryDataFileType = 5, piSelectionFileType = 6, piAll = 7 } PageInfo; typedef [uuid(D6166973-3665-4EDB-94B0-77C65C34B51C)] enum { pfOneNote = 0, pfOneNotePackage = 1, pfMHTML = 2, pfPDF = 3, pfXPS = 4, pfWord = 5, pfEMF = 6, pfHTML = 7, pfOneNote2007 = 8 } PublishFormat; typedef [uuid(E195F3E3-8EC3-4A67-81FE-DDBEC2B42D3F)] enum { slBackUpFolder = 0, slUnfiledNotesSection = 1, slDefaultNotebookFolder = 2 } SpecialLocation; typedef [uuid(452D048E-7F61-4258-94B9-A39E19C290DA)] enum { flEMail = 0, flContacts = 1, flTasks = 2, flMeetings = 3, flWebContent = 4, flPrintOuts = 5 } FilingLocation; typedef [uuid(82FC5A95-FEB7-4242-95E1-369C5DFE3F49)] enum { fltNamedSectionNewPage = 0, fltCurrentSectionNewPage = 1, fltCurrentPage = 2, fltNamedPage = 4 } FilingLocationType; typedef [uuid(226CC8E6-1ED0-4770-A7F1-A80BB4DDF07B)] enum { npsDefault = 0, npsBlankPageWithTitle = 1, npsBlankPageNoTitle = 2 } NewPageStyle; typedef [uuid(B67BC7E1-91B9-4F50-8471-77C76F8D63D6)] enum { dlDefault = 0xffffffff, dlNone = 0, dlLeft = 1, dlRight = 2, dlTop = 3, dlBottom = 4 } DockLocation; typedef [uuid(68555133-B62F-4490-9D66-9E9BFC68F6C6)] enum { xs2007 = 0, xs2010 = 1, xs2013 = 2, xsCurrent = 2 } XMLSchema; typedef [uuid(1ECC88B3-6D2B-4EDD-8DD5-BB11E5D34C09)] enum { tcsExpanded = 0, tcsCollapsed = 1 } TreeCollapsedStateType; typedef [uuid(13F18B04-E76F-42E0-97E6-8B6ABF38B484)] enum { nfoLocal = 1, nfoNetwork = 2, nfoWeb = 4, nfoNoWacUrl = 8 } NotebookFilterOutType; [ odl, uuid(1D12BD3F-89B6-4077-AA2C-C9DC2BCA42F9), helpstring("IQuickFilingUI Interface"), dual, oleautomation ] interface IQuickFilingDialog : IDispatch { [id(00000000), propget] HRESULT Title([out, retval] BSTR* bstrTitle); [id(00000000), propput] HRESULT Title([in] BSTR bstrTitle); [id(0x00000001), propget] HRESULT Description([out, retval] BSTR* bstrDescription); [id(0x00000001), propput] HRESULT Description([in] BSTR bstrDescription); [id(0x00000002), propget] HRESULT CheckboxText([out, retval] BSTR* bstrText); [id(0x00000002), propput] HRESULT CheckboxText([in] BSTR bstrText); [id(0x00000003), propget] HRESULT CheckboxState([out, retval] VARIANT_BOOL* pfChecked); [id(0x00000003), propput] HRESULT CheckboxState([in] VARIANT_BOOL pfChecked); [id(0x00000004), propget] HRESULT WindowHandle([out, retval] uint64* pHWNDWindow); [id(0x00000005), propget] HRESULT TreeDepth([out, retval] HierarchyElement* pTreeDepth); [id(0x00000005), propput] HRESULT TreeDepth([in] HierarchyElement pTreeDepth); [id(0x00000006), propget] HRESULT ParentWindowHandle([out, retval] uint64* pHWNDParentWindow); [id(0x00000006), propput] HRESULT ParentWindowHandle([in] uint64 pHWNDParentWindow); [id(0x00000007), propget] HRESULT Position([out, retval] tagPOINT* pPoint); [id(0x00000007), propput] HRESULT Position([in] tagPOINT pPoint); [id(0x00000008)] HRESULT SetRecentResults( [in] RecentResultType recentResults, [in] VARIANT_BOOL fShowCurrentSection, [in] VARIANT_BOOL fShowCurrentPage, [in] VARIANT_BOOL fShowUnfiledNotes); [id(0x0000000a)] HRESULT AddButton( [in] BSTR bstrText, [in] HierarchyElement allowedElements, [in] HierarchyElement allowedReadOnlyElements, [in] VARIANT_BOOL fDefault); [id(0x0000000b)] HRESULT Run([in] IQuickFilingDialogCallback* piCallback); [id(0x0000000c), propget] HRESULT SelectedItem([out, retval] BSTR* pbstrSelectedNodeID); [id(0x0000000d), propget] HRESULT PressedButton([out, retval] unsigned long* pButtonIndex); [id(0x0000000e), propput] HRESULT TreeCollapsedState([in] TreeCollapsedStateType rhs); [id(0x0000000f), propput] HRESULT NotebookFilterOut([in] NotebookFilterOutType rhs); [id(0x00000010)] HRESULT ShowCreateNewNotebook(); [id(0x00000011)] HRESULT AddInitialEditor(BSTR initialEditor); [id(0x00000012)] HRESULT ClearInitialEditors(); [id(0x00000013)] HRESULT ShowSharingHyperlink(); }; typedef struct tagtagPOINT { long x; long y; } tagPOINT; [ odl, uuid(627EA7B4-95B5-4980-84C1-9D20DA4460B1), helpstring("IQuickFilingDialogCallback Interface"), dual, oleautomation ] interface IQuickFilingDialogCallback : IDispatch { [id(0x60020000)] HRESULT OnDialogClosed([in] IQuickFilingDialog* dialog); }; [ odl, uuid(452AC71A-B655-4967-A208-A4CC39DD7949), helpstring("IApplication Interface"), dual, oleautomation ] interface IApplication : IDispatch { [id(0x60020000)] HRESULT GetHierarchy( [in] BSTR bstrStartNodeID, [in] HierarchyScope hsScope, [out] BSTR* pbstrHierarchyXmlOut, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020001)] HRESULT UpdateHierarchy( [in] BSTR bstrChangesXmlIn, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020002)] HRESULT OpenHierarchy( [in] BSTR bstrPath, [in] BSTR bstrRelativeToObjectID, [out] BSTR* pbstrObjectID, [in, optional, defaultvalue(0)] CreateFileType cftIfNotExist); [id(0x60020003)] HRESULT DeleteHierarchy( [in] BSTR bstrObjectID, [in, optional, defaultvalue(00:00:00)] DATE dateExpectedLastModified, [in, optional, defaultvalue(0)] VARIANT_BOOL deletePermanently); [id(0x60020004)] HRESULT CreateNewPage( [in] BSTR bstrSectionID, [out] BSTR* pbstrPageID, [in, optional, defaultvalue(0)] NewPageStyle npsNewPageStyle); [id(0x60020005)] HRESULT CloseNotebook( [in] BSTR bstrNotebookID, [in, optional, defaultvalue(0)] VARIANT_BOOL force); [id(0x60020006)] HRESULT GetHierarchyParent( [in] BSTR bstrObjectID, [out] BSTR* pbstrParentID); [id(0x60020007)] HRESULT GetPageContent( [in] BSTR bstrPageID, [out] BSTR* pbstrPageXmlOut, [in, optional, defaultvalue(0)] PageInfo pageInfoToExport, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020008)] HRESULT UpdatePageContent( [in] BSTR bstrPageChangesXmlIn, [in, optional, defaultvalue(00:00:00)] DATE dateExpectedLastModified, [in, optional, defaultvalue(2)] XMLSchema xsSchema, [in, optional, defaultvalue(0)] VARIANT_BOOL force); [id(0x60020009)] HRESULT GetBinaryPageContent( [in] BSTR bstrPageID, [in] BSTR bstrCallbackID, [out] BSTR* pbstrBinaryObjectB64Out); [id(0x6002000a)] HRESULT DeletePageContent( [in] BSTR bstrPageID, [in] BSTR bstrObjectID, [in, optional, defaultvalue(00:00:00)] DATE dateExpectedLastModified, [in, optional, defaultvalue(0)] VARIANT_BOOL force); [id(0x6002000b)] HRESULT NavigateTo( [in] BSTR bstrHierarchyObjectID, [in, optional, defaultvalue("")] BSTR bstrObjectID, [in, optional, defaultvalue(0)] VARIANT_BOOL fNewWindow); [id(0x6002000c)] HRESULT NavigateToUrl( [in] BSTR bstrUrl, [in, optional, defaultvalue(0)] VARIANT_BOOL fNewWindow); [id(0x6002000d)] HRESULT Publish( [in] BSTR bstrHierarchyID, [in] BSTR bstrTargetFilePath, [in, optional, defaultvalue(0)] PublishFormat pfPublishFormat, [in, optional, defaultvalue("")] BSTR bstrCLSIDofExporter); [id(0x6002000e)] HRESULT OpenPackage( [in] BSTR bstrPathPackage, [in] BSTR bstrPathDest, [out] BSTR* pbstrPathOut); [id(0x6002000f)] HRESULT GetHyperlinkToObject( [in] BSTR bstrHierarchyID, [in] BSTR bstrPageContentObjectID, [out] BSTR* pbstrHyperlinkOut); [id(0x60020010)] HRESULT FindPages( [in] BSTR bstrStartNodeID, [in] BSTR bstrSearchString, [out] BSTR* pbstrHierarchyXmlOut, [in, optional, defaultvalue(0)] VARIANT_BOOL fIncludeUnindexedPages, [in, optional, defaultvalue(0)] VARIANT_BOOL fDisplay, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020011)] HRESULT FindMeta( [in] BSTR bstrStartNodeID, [in] BSTR bstrSearchStringName, [out] BSTR* pbstrHierarchyXmlOut, [in, optional, defaultvalue(0)] VARIANT_BOOL fIncludeUnindexedPages, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020012)] HRESULT GetSpecialLocation( [in] SpecialLocation slToGet, [out] BSTR* pbstrSpecialLocationPath); [id(0x60020013)] HRESULT MergeFiles( [in] BSTR bstrBaseFile, [in] BSTR bstrClientFile, [in] BSTR bstrServerFile, [in] BSTR bstrTargetFile); [id(0x60020014)] HRESULT QuickFiling([out, retval] IQuickFilingDialog** ppiDialog); [id(0x60020015)] HRESULT SyncHierarchy([in] BSTR bstrHierarchyID); [id(0x60020016)] HRESULT SetFilingLocation( [in] FilingLocation flToSet, [in] FilingLocationType fltToSet, [in] BSTR bstrFilingSectionID); [id(0x00000064), propget] HRESULT Windows([out, retval] Windows** ppONWindows); [id(0x00000066), propget, hidden] HRESULT Dummy1([out, retval] VARIANT_BOOL* pBool); [id(0x60020019)] HRESULT MergeSections( [in] BSTR bstrSectionSourceId, [in] BSTR bstrSectionDestinationId); [id(0x00000068), propget] HRESULT COMAddIns([out, retval] IDispatch** ppiComAddins); [id(0x00000069), propget] HRESULT LanguageSettings([out, retval] IDispatch** ppiLanguageSettings); [id(0x6002001c)] HRESULT GetWebHyperlinkToObject( [in] BSTR bstrHierarchyID, [in] BSTR bstrPageContentObjectID, [out] BSTR* pbstrHyperlinkOut); }; [ odl, uuid(6D4B9C3E-CC05-493F-85E2-43D1006DF96A), helpstring("List of our Windows Interface"), dual, oleautomation ] interface Windows : IDispatch { [id(00000000), propget] HRESULT Item( [in] unsigned long Index, [out, retval] Window** Item); [id(0x00000001), propget] HRESULT Count([out, retval] unsigned long* Count); [id(0xfffffffc), propget] HRESULT _NewEnum([out, retval] IUnknown** _NewEnum); [id(0x00000003), propget] HRESULT CurrentWindow([out, retval] Window** ppCurrentWindow); }; [ odl, uuid(8E8304B8-CBD1-44F8-B0E8-89C625B2002E), helpstring("Window Interface"), dual, oleautomation ] interface Window : IDispatch { [id(00000000), propget] HRESULT WindowHandle([out, retval] uint64* pHWNDWindow); [id(0x00000001), propget] HRESULT CurrentPageId([out, retval] BSTR* pbstrPageObjectId); [id(0x00000002), propget] HRESULT CurrentSectionId([out, retval] BSTR* pbstrSectionObjectId); [id(0x00000003), propget] HRESULT CurrentSectionGroupId([out, retval] BSTR* pbstrSectionObjectId); [id(0x00000004), propget] HRESULT CurrentNotebookId([out, retval] BSTR* pbstrNotebookObjectId); [id(0x00000009)] HRESULT NavigateTo( [in] BSTR bstrHierarchyObjectID, [in, optional, defaultvalue("0")] BSTR bstrObjectID); [id(0x0000000a), propget] HRESULT FullPageView([out, retval] VARIANT_BOOL* pIsFullPageView); [id(0x0000000a), propput] HRESULT FullPageView(VARIANT_BOOL pIsFullPageView); [id(0x0000000b), propget] HRESULT Active([out, retval] VARIANT_BOOL* pIsActive); [id(0x0000000b), propput] HRESULT Active(VARIANT_BOOL pIsActive); [id(0x0000000d), propget] HRESULT DockedLocation([out, retval] DockLocation* pDockLocation); [id(0x0000000d), propput] HRESULT DockedLocation(DockLocation pDockLocation); [id(0x0000000e), propget] HRESULT Application([out, retval] IApplication** ppiApp); [id(0x0000000f), propget] HRESULT SideNote([out, retval] VARIANT_BOOL* pIsSideNote); [id(0x00000010)] HRESULT NavigateToUrl([in] BSTR bstrUrl); [id(0x00000011)] HRESULT SetDockedLocation( [in] DockLocation DockLocation, [in] tagPOINT ptMonitor); }; [ uuid(E2E1511D-502D-4BD0-8B3A-8A89A05CDCAE), helpstring("IOneNoteEvents Interface"), nonextensible ] dispinterface IOneNoteEvents { properties: methods: [id(0x00000001)] void OnNavigate(); [id(0x00000002)] void OnHierarchyChange([in] BSTR bstrActivePageID); }; [ uuid(D7FAC39E-7FF1-49AA-98CF-A1DDD316337E), version(1.0), helpstring("Application Class") ] coclass Application { [default] interface IApplication; [default, source] dispinterface IOneNoteEvents; }; typedef [uuid(D3F5A756-4BAC-4D3D-9BAF-90935121AAA6)] enum { hrMalformedXML = 0x80042000, hrInvalidXML = 0x80042001, hrCreatingSection = 0x80042002, hrOpeningSection = 0x80042003, hrSectionDoesNotExist = 0x80042004, hrPageDoesNotExist = 0x80042005, hrFileDoesNotExist = 0x80042006, hrInsertingImage = 0x80042007, hrInsertingInk = 0x80042008, hrInsertingHtml = 0x80042009, hrNavigatingToPage = 0x8004200a, hrSectionReadOnly = 0x8004200b, hrPageReadOnly = 0x8004200c, hrInsertingOutlineText = 0x8004200d, hrPageObjectDoesNotExist = 0x8004200e, hrBinaryObjectDoesNotExist = 0x8004200f, hrLastModifiedDateDidNotMatch = 0x80042010, hrGroupDoesNotExist = 0x80042011, hrPageDoesNotExistInGroup = 0x80042012, hrNoActiveSelection = 0x80042013, hrObjectDoesNotExist = 0x80042014, hrNotebookDoesNotExist = 0x80042015, hrInsertingFile = 0x80042016, hrInvalidName = 0x80042017, hrFolderDoesNotExist = 0x80042018, hrInvalidQuery = 0x80042019, hrFileAlreadyExists = 0x8004201a, hrSectionEncryptedAndLocked = 0x8004201b, hrDisabledByPolicy = 0x8004201c, hrNotYetSynchronized = 0x8004201d, hrLegacySection = 0x8004201e, hrMergeFailed = 0x8004201f, hrInvalidXMLSchema = 0x80042020, hrFutureContentLoss = 0x80042022, hrTimeOut = 0x80042023, hrRecordingInProgress = 0x80042024, hrUnknownLinkedNoteState = 0x80042025, hrNoShortNameForLinkedNote = 0x80042026, hrNoFriendlyNameForLinkedNote = 0x80042027, hrInvalidLinkedNoteUri = 0x80042028, hrInvalidLinkedNoteThumbnail = 0x80042029, hrImportLNTThumbnailFailed = 0x8004202a, hrUnreadDisabledForNotebook = 0x8004202b, hrInvalidSelection = 0x8004202c, hrConvertFailed = 0x8004202d, hrRecycleBinEditFailed = 0x8004202e, hrAppInModalUI = 0x80042030 } Error; [ uuid(DC67E480-C3CB-49F8-8232-60B0C2056C8E), version(1.0), helpstring("Application2 Class") ] coclass Application2 { [default] interface IApplication; [default, source] dispinterface IOneNoteEvents; }; }; So far, I didn't manage to be able to interact with it : There is my code (based on same issue someone had in 2011
      #AutoIt3Wrapper_UseX64=n #include <Array.au3> #include "AutoItObject\AutoItObject.au3" ;=============================================================================== ;interface "OneNoteIApplication" Global Const $sCLSID_OneNoteApplication = "{0039FFEC-A022-4232-8274-6B34787BFC27}" Global Const $sIID_IOneNoteApplication = "{2DA16203-3F58-404F-839D-E4CDE7DD0DED}" ; Definition Global $dtagIOneNoteWindows = $dtagIDispatch Global $dtagIOneNoteApplication = $dtagIDispatch & _ "GetHierarchy hresult(bstr;dword;bstr*);" & _ "UpdateHierarchy hresult(bstr);" & _ "OpenHierarchy hresult(bstr;bstr;bstr*;dword);" & _ "DeleteHierarchy hresult(bstr;double);" & _ "CreateNewPage hresult(bstr;bstr*;dword);" & _ "CloseNotebook hresult(bstr);" & _ "GetHierarchyParent hresult(bstr;bstr*);" & _ "GetPageContent hresult(bstr;bstr*;dword);" & _ "UpdatePageContent hresult(bstr;double);" & _ "GetBinaryPageContent hresult(bstr;bstr;bstr*);" & _ "DeletePageContent hresult(bstr;bstr;dword);" & _ "NavigateTo hresult(bstr;bstr;bool);" & _ "Publish hresult(bstr;bstr;dword;bstr);" & _ "OpenPackage hresult(bstr;bstr;bstr*);" & _ "GetHyperlinkToObject hresult(bstr;bstr;bstr*);" & _ "FindPages hresult(bstr;bstr;bstr*;bool;bool);" & _ "FindMeta hresult(bstr;bstr;bstr*;bool);" & _ "GetSpecialLocation hresult(dword;bstr*);" ; List Global $ltagIOneNoteApplication = $ltagIDispatch & _ "GetHierarchy;" & _ "UpdateHierarchy;" & _ "OpenHierarchy;" & _ "DeleteHierarchy;" & _ "CreateNewPage;" & _ "CloseNotebook;" & _ "GetHierarchyParent;" & _ "GetPageContent;" & _ "UpdatePageContent;" & _ "GetBinaryPageContent;" & _ "DeletePageContent;" & _ "NavigateTo;" & _ "Publish;" & _ "OpenPackage;" & _ "GetHyperlinkToObject;" & _ "FindPages;" & _ "FindMeta;" & _ "GetSpecialLocation;" ;=============================================================================== _AutoItObject_StartUp() Global $objOneNote = ObjCreate("OneNote.Application") Global $pOneNote = _AutoItObject_IDispatchToPtr($objOneNote) _AutoItObject_IUnknownAddRef($objOneNote) Global $oOneNote = _AutoItObject_WrapperCreate($pOneNote, $dtagIOneNoteWindows) ;~ Global $oOnenote = ObjCreateInterface($sCLSID_OneNoteApplication,$sIID_IOneNoteApplication,$dtagIOneNoteApplication,True) ;~ ; Check if object is created: If Not IsObj($oOneNote) Then MsgBox(48, "Error", "Object not created. Something is wrong.") Exit EndIf $aCall = $oOneNote.GetTypeInfoCount(0) $iTypeInfoCount = $aCall[1] ConsoleWrite("$iTypeInfoCount = " & $iTypeInfoCount & @CRLF) $Window = $oOneNote.Windows ;~ ConsoleWrite("Test = " & $Window.CurrentPageId & @CRLF) $str = "onenote:///R:\Software\OneNote%20EOD\EOD%20Scrum\Sprint%20136.one#section-id={D2EB7AEB-362B-490A-9CE0-0B9316DF0DAD}&end" $hBSTR = DllCall("oleaut32.dll", "ptr", "SysAllocString", "wstr", $str) $aCall = $oOnenote.NavigateToUrl($hBSTR[0])  
      Can someone help me to go in the good direction? I'm a little lost with what's needed, (CLSID and IID whereas I have only a UUID and can't find a good starting doc online)
      Thanks a lot,
       
×