Results 1 to 3 of 3

Thread: Remove or delete firewall rule in windows xp problem

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2019
    Posts
    44

    Remove or delete firewall rule in windows xp problem

    Code:
    Public Sub RemoveFirewallRules(ByVal Optional RuleName As String = "Test")
            Try
                Dim tNetFwPolicy2 As Type = Type.GetTypeFromProgID("HNetCfg.FwPolicy2")
                Dim fwPolicy2 As INetFwPolicy2 = CType(Activator.CreateInstance(tNetFwPolicy2), INetFwPolicy2)
                Dim currentProfiles = fwPolicy2.CurrentProfileTypes
                Dim RuleList As List(Of INetFwRule) = New List(Of INetFwRule)()
                Dim rule As INetFwRule
                i = 0
                For Each rule In fwPolicy2.Rules
                    If rule.Name.IndexOf(RuleName) <> -1 Then
                        Dim firewallPolicy As INetFwPolicy2 = CType(Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2")), INetFwPolicy2)
                        firewallPolicy.Rules.Remove(rule.Name)
                        i = i + 1
                    End If
                Next
                End
                If i <> 0 Then
                    MsgBox(RuleName & " has been deleted from Firewall Policy")
                End If
    
            Catch r As Exception
                MsgBox(r.Message)
            End Try
        End Sub
    I have the code above that works on Windows 7 and above.
    The code does not work with Windows XP. I also need to have the code in windows xp because we still have that operating system.

    When I run the program on windows xp, it will throw error "VALUE CANNOT BE NULL. PARAMETER NAME: TYPE"

    What I want to achieve is to delete unwanted or unauthorized firewall entries programmatically which I will be comparing to list of allowed firewall names on a text file.

    I just need to delete it by firewall rule name and not by other way.

    Hoping for someone to help.
    Last edited by techbee; Jan 14th, 2020 at 10:40 PM.

  2. #2

  3. #3
    New Member
    Join Date
    Oct 2020
    Posts
    1

    Re: Remove or delete firewall rule in windows xp problem

    Sorry for digging out this older post, currently researching similar topics, in XP you'll need to use the older Windows XP SP2 COM API, which shouldnt be used above XP, HNetCfg.FwMgr instead of your HNetCfg FwPolicy2 -
    Code:
    Dim fwMgr0 = CreateObject("HNetCfg.FwMgr")
    Dim FWlpCP0 = fwMgr0.LocalPolicy.CurrentProfile

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width