C # (VB. NET) Operating Windows built-in firewall addition/deletion allow exceptions through the firewall

Source: Internet
Author: User

In the previous articles, I talked about some operations on the firewall. What do I do today?AddAndDeleteAllow firewall programs to enter the exception list

In this article, we use com references, because the operations are too complicated without com references.

1. Add com references

In reference, select the com page and findNetfwtypelib, OK

II. Introduction of namespaces

using NetFwTypeLib;

3. Add exceptions that allow access through the firewall

// Create an instance of the firewall management class, inetfwmgr netfwmgr = (inetfwmgr) activator. createinstance (type. gettypefromprogid ("hnetcfg. fwmgr "); // create an instance of the authentication program class inetfwauthorizedapplication APP = (inetfwauthorizedapplication) activator. createinstance (type. gettypefromprogid ("hnetcfg. fwauthorizedapplication "); // In the exception list, the name displayed by the program is app. name = "Custom"; // specifies the path of the program. The app is used here. processimagefilename = application. executablepath; // whether to enable the rule app. enabled = true; // The Management Policy netfwmgr added to the firewall. localpolicy. currentprofile. authorizedapplications. add (APP );

4. delete a program in the exception list

Inetfwmgr netfwmgr = (inetfwmgr) activator. createinstance (type. gettypefromprogid ("hnetcfg. fwmgr "); // The parameter is the absolute path of the program netfwmgr. localpolicy. currentprofile. authorizedapplications. remove (application. executablepath );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.