Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
Hi All,

I am trying to add an exception in windows firewall allowed program list.

My app is in .net framework 3.5:
the below link am not able to compile it compiled in framework 4.0
Open Windows Firewall During Installation[^]

I also used the below code
C#
void AddToFirewallException(string ApplicationName, string FilePath)
        {
            // Add exception to windows firewall after installation
            string RegPath =
                @"SYSTEM\ControlSet001\Services\SharedAccess\Parameters\
        FirewallPolicy\StandardProfile\AuthorizedApplications\List";
            string KeyValue = FilePath + ":*:Enabled:" + ApplicationName;

            RegistryKey Key = Registry.LocalMachine.OpenSubKey(RegPath, true);
            Key.SetValue(FilePath, KeyValue);
            Key.Close();
            Key = null;
        }

the above code also works fine when called from a winform, but raise an exception when I called it in the custom action in VS setup project, Actually I want to add my app in the allowed program list during the installation.

Regards,
Nitin
Posted
Comments
[no name] 29-May-11 17:15pm    
Are you running the setup as administrator? Same for windows app? Making settings to the firewall requires elevated privledges, after all what good it do to have any application run by any user add hole in the firewall?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900