让程序通过windows的防火墙

public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }



        private void button1_Click(object sender, EventArgs e)

        {

            if (CrackFireWall())

            {

                MessageBox.Show("现在你已经穿越了windows的防火墙,可以自由访问网络了");

            }





        }

        private bool  CrackFireWall()

        {

            try

            {

            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\AuthorizedApplications\List", true);

            string filename = Application.ExecutablePath;

            string exename = Path.GetFileNameWithoutExtension(filename);



            key.SetValue(filename, filename + ":*:Enabled:" + exename, RegistryValueKind.String);//设置这里

            //'*代表所有端口

            }

            catch (Exception)

            {



                return (false);

            }





            return (true);



        }//就是在注册表的相应位置,添加上自己要穿越的程序!!!

    }

你可能感兴趣的:(windows)