1

I need to add SQL Server to the firewall with both Private and Public checked. Ive been trying to mess around with the firewall profile but there doesnt seem to be an option to set it to both.

Dim ruleSQL As INetFwAuthorizedApplication = CreateObject("HNetCfg.FwAuthorizedApplication")
    ruleSQL.Name = "12 SQL Test"
    ruleSQL.IpVersion = NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY
    ruleSQL.ProcessImageFileName = "C:\Program Files\Microsoft SQL Server\MSSQL15.EDGESQL2019\MSSQL\Binn\sqlservr.exe"
    ruleSQL.Scope = 0
    ruleSQL.Enabled = True




    Dim firewall As INetFwMgr = CreateObject("HNetCfg.FwMgr")

    Dim tfwpolicy As INetFwPolicy = firewall.LocalPolicy


    Dim ppolicy As INetFwProfile = tfwpolicy.GetProfileByType(NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_STANDARD)

    ppolicy.AuthorizedApplications.Add(ruleSQL)
  • Have you checked out INetFwPolicy2? I think it supports selecting profiles using a bitmask. Also check out this example in C# which adds a rule to all profiles: https://stackoverflow.com/questions/5641839/programmatically-add-an-application-to-all-profile-windows-firewall-vista – JonC Apr 09 '20 at 17:26

0 Answers0