Jump to content

Check if Win Firewall is on (or off)


Crash
 Share

Recommended Posts

I understand that to ON firewall in XP or older version needs the script

Run(@ComSpec & " /c " & 'netsh firewall set opmode Enable', "", @SW_HIDE)

and to OFF it requires the script

Run(@ComSpec & " /c " & 'netsh firewall set opmode Disable', "", @SW_HIDE)

Meanwhile,

To ON in on Vista or Win7, needs

Run(@ComSpec & " /c " & 'netsh advfirewall set currentprofile state on', "", @SW_HIDE)

and to OFF it needs

Run(@ComSpec & " /c " & 'netsh advfirewall set currentprofile state off', "", @SW_HIDE)

But is there any scripts to CHECK if the firewall is on?

I am writing a program to let the user to turn the firewall ON and OFF, and there is a part I need to check if the firewall is on or not.

If my program setting is on, but the firewall is not, my script will turn it on. Vice versa if it is off.

I have tried to loop the on command repeatedly if the setting is on, but that will hang the computer. Sleep won't work either, because that will slow the respond from GUI.

So to be simple, how can I check if the firewall is on?

Thanks in advance!

Edited by Crash

JPGRARMouse Lock | My website | Thanks so much for your help! ❤️

Link to comment
Share on other sites

Read the registry bit.

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\WindowsFirewall\DomainProfile\EnableFirewall

That should work.

I understand that to ON firewall in XP or older version needs the script

Run(@ComSpec & " /c " & 'netsh firewall set opmode Enable', "", @SW_HIDE)

and to OFF it requires the script

Run(@ComSpec & " /c " & 'netsh firewall set opmode Disable', "", @SW_HIDE)

Meanwhile,

To ON in on Vista or Win7, needs

Run(@ComSpec & " /c " & 'netsh advfirewall set currentprofile state on', "", @SW_HIDE)

and to OFF it needs

Run(@ComSpec & " /c " & 'netsh advfirewall set currentprofile state off', "", @SW_HIDE)

But is there any scripts to CHECK if the firewall is on?

I am writing a program to let the user to turn the firewall ON and OFF, and there is a part I need to check if the firewall is on or not.

If my program setting is on, but the firewall is not, my script will turn it on. Vice versa if it is off.

I have tried to loop the on command repeatedly if the setting is on, but that will hang the computer. Sleep won't work either, because that will slow the respond from GUI.

So to be simple, how can I check if the firewall is on?

Thanks in advance!

Link to comment
Share on other sites

  • 2 weeks later...

It's possible that the firewall service might be turned on, but the firewall is disabled, checking the registry is probably the best way to check if the firewall is on.

You're right. But in any case, the registry should not be read to determine if the firewall is on or not. It's all nicely wrapped somewhere with a public interface, I just don't remember where to look.
Link to comment
Share on other sites

; if firewall is turn off value =0      
; if fwl is on value =1
If @UserName = IsAdmin() Then
    MsgBox(64, "You Have No Enought Privelegies For Acess Firewall", "You Have No Enought Privelegies For Manipulate  Firewall!")
    Exit
    Else
    MsgBox(64, "Admin Rights Detected","Admin Rights Detected.")
    
    EndIf
$a = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\", "EnableFirewall")

if $a ="1" Then
    MsgBox(64,"Firewall is ON", "Firewall is On Value is Equal to =>" & $a)
Else
    
    RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile", "EnableFirewall", "REG_DWORD", "1")
    MsgBox(64, "Turned ON", "Firewall Is Turned ON")
    EndIf

[size="5"] [/size]
Link to comment
Share on other sites

I don't know enough about what you are trying to do but would like to point out a flaw in the reasoning -

On our systems at work, in order to pass compliance inspections, they are configured for the local firewall to be running. For management purposes, we turn the firewall off by Group Policy. The compliance auditing software finds the correct registry keys in the correct places to assume the firewall is running. As pointed out earlier, the service running is no guarantee that the firewall in enabled.

Now if your only wish is to set the state of the service, any time I try to start a service that is already started or stop a service that is already stopped, I don't seem to have any issues, but that is from a command prompt and not from inside AutoIt and using sc stop <servicename> or sc start <servicename> instead of netsh.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...