dcsimg
Results 1 to 2 of 2

Thread: Remove or delete firewall rule in windows xp problem

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2019
    Posts
    43

    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

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width