110,536
社区成员
发帖
与我相关
我的任务
分享
class Program {
static void Main(string[] args) {
Console.WriteLine(IsEnabled());
AddToException(@"c:\myprogram.exe", "My Program");
Console.ReadLine();
}
public static bool IsEnabled() {
RegistryKey key = Registry.LocalMachine.OpenSubKey(KEY_BASE);
object value = key.GetValue("EnableFirewall");
if(value == null) {
return false;
}
return true;
}
public static void AddToException(string path, string dispName) {
RegistryKey key = Registry.LocalMachine.OpenSubKey(KEY_BASE);
key = key.OpenSubKey(@"AuthorizedApplications\List",true);
key.SetValue(path,string.Format("{0}:*:Enabled:{1}",path,dispName));
}
private static readonly string KEY_BASE =
@"SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile";
}