how can i use to add a program or a post to windows firewall

miketayo used Ask the Experts™
Hi, experts

i need to add a program and port number under ycp and udp to windows firewall using  by specifying the system name, program location, port number etc

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You need to use classic APIs (COM) as there are no classes inside .Net to manage the firewall

See how at:
You could try the shell function to run the net.exe firewall command eg
You would have to run as Adminstrator in vista if UAC was on though..
Dim strYourAppPath As String = "C:\yourapp\yourapp.exe"
Dim strYourAppName As String = "YourApp"
'this would add the application as a rule to windows firewall
'add allowedprogram C:\MyApp\MyApp.exe "My Application" ENABLE
Shell(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\netsh.exe firewall add allowedprogram " & strYourAppPath & " """ & strYourAppName & """ " & "ENABLE", AppWinStyle.NormalFocus)
'to add a specific port you could try
'netsh firewall add portopening TCP 333 yourRuleName enable subnet
Shell(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\netsh.exe firewall add portopening TCP 33 """ & strYourAppName & """ ENABLE subnet", AppWinStyle.NormalFocus)

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial