Access Vista Firewall

Source: Internet
Author: User
There is a big difference between firewall access and XP Access in Vista.
XP has two methods, but Vista does not fully analyze all firewall settings.
I will share my personal experiences with you first

1. Access through the registry:

Many firewall settings are stored in the registry. The specific key values are as follows:
The content in domainprofile under HKEY_LOCAL_MACHINE \ CurrentControlSet \ Services \ sharedaccess \ Parameters \ firewallpolicy is the information stored after the machine is added to the domain.
The content in standardprofile is the information that the machine is not added to the domain for storage.

The two keys also have three key values.
Enablefirewall: Firewall Enabled
Donotallowexceptions: Exceptions not allowed
Disablenotifications: prompt message

There are also two subkeys under these two keys
Authorizedapplications: applications that are allowed to passProgram
Globallyopenports: opened port

The firewall settings for accessing XP using the registry are basically correct, but this method is not applicable in Vista.
Vista changes a lot in the key value of the registry, and does not change the firewall settings.
If you are interested, try the registry key value in Vista:
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ sharedaccess
There are two sub-key directories, default and parameters, both of which store corresponding settings.

2. Access through DLL:

. NET development requires the use of hnetcfg. dll
For C/C ++ development, you also need to use the header file netfw. H. For XP and Vista, You need to download the corresponding SDK to have this header file.

Here we will introduce the. NET development details. After adding the DLL to the project, three namespaces will appear on the project reference, natupnplib, netconlib, and netfwtypelib.
All firewall settings are in netfwtypelib, and the other two are of interest.
Main interfaces used:
Inetfwauthorizedapplications: All applications that are allowed to pass
Inetfwservices: All service and service ports allowed
Inetfwpolicy: Firewall Policy
Inetfwprofile: firewall settings
Inetfwmgr: firewall management class

Netfwtypelib is an interface in this namespace. Class instances can only be obtained through reflection. The entry is inetfwmgr.

ReferenceCode:


1 Type typfwmgr =   Null ;
2 Netfwtypelib. inetfwauthorizedapplications iapps =   Null ;
3 Netfwtypelib. inetfwservices iservices =   Null ;
4 Netfwtypelib. inetfwmgr ifwmgr =   Null ;
5 Netfwtypelib. inetfwpolicy ifwpolicy =   Null ;
6 Netfwtypelib. inetfwprofile ifwprofile =   Null ;
7 Typfwmgr = Type. gettypefromclsid ( New GUID ( " {304ce942-6e39-40d8-943a-b913c40c9cd4} " ));
8
9 Ifwmgr = (Netfwtypelib. inetfwmgr) activator. createinstance (typfwmgr );
10 Ifwpolicy = Ifwmgr. localpolicy;
11 Ifwprofile = Ifwpolicy. currentprofile;
12
13 Bool Isfireenabled = Ifwprofile. firewallenabled;
14 Bool Isfireexception = Ifwprofile. exceptionsnotallowed;
15
16 Iapps = Ifwprofile. authorizedapplications;
17 Iservices = Ifwprofile. Services;
18
19 System. Console. writeline ( " Firewall Enabled: {0} " , Isfireenabled );
20 System. Console. writeline ( " Firewall exceptionsnotallowed: {0} \ n " , Isfireexception );
21
22 Foreach (Netfwtypelib. inetfwauthorizedapplication iapp In Iapps)
23 {
24 System. Console. writeline ( " Application name is: \ n {0} \ n " , Iapp. Name );
25 System. Console. writeline ( " Application processimagefilename is: \ n {0} \ n " , Iapp. processimagefilename );
26 }
27
28 Foreach (Netfwtypelib. inetfwservice iservice In Iservices)
29 {
30 If (Iservice. enabled)
31 {
32 System. Console. writeline ( " Service name is: \ n {0} " , Iservice. Name );
33 Foreach (Netfwtypelib. inetfwopenport iport In Iservice. globallyopenports)
34 {
35System. Console. writeline ("{0} {1}", Iport. Port, iport. Name );
36}
37 System. Console. writeline ();
38 }
39 }

Type. gettypefromclsid indicates the type associated with the specified class identifier.
The GUID is obtained by checking the Registry. You can search for the namespace.
This method is not very good. If you have a better method, please let me know. Thank you.

To access the firewall in this way, there is no problem in xp. In Vista, all applications and service ports added by the user cannot be obtained, the application and service port added by the user cannot be found in the registry, and the storage location may be incorrect. In the futureArticle.

References:
. Net: http://blog.csdn.net/mittermeyer/archive/2006/05/19/745856.aspx
C/C ++: http://blog.csdn.net/Y___Y/archive/2007/03/22/1537493.aspx

Supplement:
Access using DLL. If it is developed under Vista, use firewallapi. dll under windows \ system32.
After adding the DLL, only one namespace will appear on the project reference, that is, netfwtypelib

Search for the CLSID method of the Registry and search for firewall. You only need to find three sub-key directories in a CLSID. The last one is progid, which has a unique key value, that is, the class name is saved.

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.