Batch file or script to allow ports and programs in Win7 Firewall

Posted on 2011-04-27
Last Modified: 2012-05-11
I have a number of TCP and UDP ports and a few exe's that need to be allowed for both inbound and outbound in the windows 7 (pro) firewall.
I've got 7 new PC's to build up and was wondering if there was a script or batch file I could modify to run on each PC.  
I used to have one for our WinXP systems, but this won't work on the Win7 firewall.

Thanks in advance.
Question by:Reece Dodds
    LVL 77

    Expert Comment

    by:David Johnson, CD, MVP
    instead of netsh firewall you need to use netsh advfirewall firewall as shown here
    LVL 7

    Author Comment

    by:Reece Dodds
    so...  adding ports is done with what string???

    for the XP script I was using:

    echo Adding firewall exception for TCP Port 50808.
    netsh advfirewall firewall add portopening protocol=TCP port=50808 name="Avaya Port 50808 TCP" mode=ENABLE scope=ALL profile=ALL

    I gather this will be different for Win7 because of inbound and outbound rules and private/public networks.

    LVL 77

    Accepted Solution

    netsh advfirewall firewall add rule name=”My Application” dir=in action=allow program=”C:\MyApp\MyApp.exe” enable=yes remoteip=,,LocalSubnet profile=domain
    profile can be public/private/domain/all
    netsh advfirewall firewall add rule name=”Open Port 80” dir=in action=allow protocol=TCP localport=80
    or for your example
    netsh advfirewall firewall add rule name="Avaya Port 50808 TCP" dir=in action=allow protocol=TCP port=50808
    LVL 7

    Author Comment

    by:Reece Dodds
    Slight typo...

    or for your example
    netsh advfirewall firewall add rule name="Avaya Port 50808 TCP" dir=in action=allow protocol=TCP port=50808

    Should've bene localport
    But otherwise perfect for what i need.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    First some basics on Windows 7 Backup.  It has 2 components one is a file based backup which is stored in .zip files each zip is split at around 200 Megabytes and there is the Image Backup which is as the name implies a total image of the partition …
    As dyndns has reduced the capabilities of the free service, I looked around for other free providers of Dynamic DNS service. After testing several I decided to move my DNS hosting to Hurricane Electric as then domains that require dynamic hostnam…
    This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now