Windowsのファイアウォールをプログラムで通過させる
1968 ワード
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);
}// , !!!
}