Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Created January 1, 2015 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpluimers/f6744e41fbfb33b27fec to your computer and use it in GitHub Desktop.
Save jpluimers/f6744e41fbfb33b27fec to your computer and use it in GitHub Desktop.
Open a specific TCP port on the Windows Firewall (Windows Vista+)
:: open port (first argument passed to batch script, second argument is description)
:checkPrivileges
net file 1>nul 2>nul
if '%errorlevel%' == '0' ( goto :gotPrivileges ) else ( goto :getPrivileges )
:isNotAdmin
:getPrivileges
echo You need to be admin running with an elevated security token to run %0
goto :exit
:isAdmin
:gotPrivileges
netsh advfirewall firewall add rule name="Open Port %1 for %2" dir=in action=allow protocol=TCP localport=%1
:exit
::pause
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment