none
Add rule to firewall error (NetFwTypeLib)

    Dotaz

  • Hello,

    I would like to ask you for help. I am using next code (without impersonation) in WPF application and it works very well:

                                Try
                                    If impersonateValidUser("user", "", "psw") Then
                                        Dim fwRule As INetFwRule = Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"))
                                        fwRule.Name = Request.Params("IP")
                                        fwRule.Action = NET_FW_ACTION_.NET_FW_ACTION_BLOCK
                                        fwRule.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN
                                        fwRule.Enabled = True
                                        fwRule.InterfaceTypes = "All"
                                        fwRule.RemoteAddresses = Request.Params("IP")
                                        Dim fwPolicy As INetFwPolicy2 = Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"))
                                        Try
                                            If fwPolicy.Rules.Item(Request.Params("IP")) Is Nothing Then fwPolicy.Rules.Add(fwRule)
                                        Catch ex As Exception
                                            EventLog.WriteEntry("app", ex.Message & ex.StackTrace, EventLogEntryType.Error)
                                        End Try
                                        undoImpersonation()
                                    End If
                                Catch ex As Exception
                                    EventLog.WriteEntry("app", ex.Message & ex.StackTrace, EventLogEntryType.Error)
                                End Try
    
    This code is in ASP.NET page and it should add attacker IP into FW.

    Unfortunately I got error The system cannot find the file specified. (Exception from HRESULT: 0x80070002) in line:

    If fwPolicy.Rules.Item(Request.Params("IP")) Is Nothing Then fwPolicy.Rules.Add(fwRule)

    Thanks for any help.

    Miroslav

    středa 23. března 2016 11:50

Odpovědi