-2

I want a batch file that after running with standard access, checks the status of the firewall and if the firewall is disabled, start a file. But, if the firewall is enabled, show all allowed ports. Is this possible?

I am checking if the firewall is enabled or not by using the Windows registry value EnableFirewall.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile

I am not sure if this is the right way.

Community
  • 1
  • 1
csacsa
  • 1
  • 1
  • 6
  • Use [how to read registry string value from batch file](http://stackoverflow.com/q/3184738) and add a condition – wOxxOm Oct 06 '15 at 09:24

1 Answers1

1

You can get the firewalls current state using this command:

netsh advfirewall show allprofiles state

You can also use the command

netstat -ab | more

This will get a list of all the open ports and display it on screen.

enter image description here

As for reading a registry key you can use reg query:

reg query <KeyName> [{/v <ValueName> | /ve}] [/s] [/se <Separator>] [/f <Data>] [{/k | /d}] [/c] [/e] [/t <Type>] [/z]

Source: https://technet.microsoft.com/en-us/library/cc742028.aspx

09stephenb
  • 9,358
  • 15
  • 53
  • 91