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

Source: Internet
Author: User

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

 
UsingNetfwtypelib;

3. Add exceptions that allow access to the firewallProgram

// Create a firewall management instanceInetfwmgr netfwmgr = (inetfwmgr) activator. createinstance (type. gettypefromprogid ("Hnetcfg. fwmgr"));// Create an instance of the authentication program classInetfwauthorizedapplication APP = (inetfwauthorizedapplication) activator. createinstance (type. gettypefromprogid ("Hnetcfg. fwauthorizedapplication"));// The name displayed by the program in the exception listApp. Name ="Custom";// The program determines the path. Here the program itself is used.App. processimagefilename = application. executablepath;// Whether to enable this ruleApp. Enabled =True;// Add the management policy to the firewallNetfwmgr. localpolicy. currentprofile. authorizedapplications. Add (APP );

4. delete a program in the exception list

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

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.