At the moment I use this code to add my program to the Windows Firewall exception list:
The problem is that if I run this code while there is an internet connection, in Windows Firewall exception list my program will get permission only for Private Network (Profile: Private). And if I run this code while there is no internet connection, in Windows Firewall exception list my program will get permission only for Public Network (Profile: Public). How can my program get access to the All Networks (Profile: All) ?
Code:
Option Explicit
Public Function AddToFirewallExceptions(ProgramAddress As String, ProgramName As String)
Const NET_FW_SCOPE_ALL = 0
Const NET_FW_IP_VERSION_ANY = 2
Dim appAuth As Object
On Error Resume Next
With CreateObject("HNetCfg.FwMgr")
Set appAuth = CreateObject("HNetCfg.FwAuthorizedApplication")
With appAuth
.ProcessImageFileName = ProgramAddress
.Name = ProgramName
.Scope = NET_FW_SCOPE_ALL
.IpVersion = NET_FW_IP_VERSION_ANY
.Enabled = True
End With
.LocalPolicy.CurrentProfile.AuthorizedApplications.Add appAuth
Set appAuth = .LocalPolicy.CurrentProfile.AuthorizedApplications.Item(ProgramAddress)
End With
If Err Then
Exit Function
End If
End Function