Crash Posted November 23, 2009 Share Posted November 23, 2009 (edited) 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 November 23, 2009 by Crash JPGRAR | Mouse Lock | My website | Thanks so much for your help! ❤️ Link to comment Share on other sites More sharing options...
Demonic Posted November 23, 2009 Share Posted November 23, 2009 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 More sharing options...
Crash Posted November 23, 2009 Author Share Posted November 23, 2009 I think that is removed, because I can only access the key to HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft WindowsFirewall was no way to be seen! JPGRAR | Mouse Lock | My website | Thanks so much for your help! ❤️ Link to comment Share on other sites More sharing options...
deltron Posted December 1, 2009 Share Posted December 1, 2009 $fwstate = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile\", "EnableFirewall") The state might also be found in HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile Link to comment Share on other sites More sharing options...
jvanegmond Posted December 1, 2009 Share Posted December 1, 2009 You can simple check if the Windows Firewall service is running. http://www.autoitscript.com/forum/index.php?showtopic=81880 github.com/jvanegmond Link to comment Share on other sites More sharing options...
deltron Posted December 1, 2009 Share Posted December 1, 2009 You can simple check if the Windows Firewall service is running.http://www.autoitscript.com/forum/index.php?showtopic=81880It'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. Link to comment Share on other sites More sharing options...
jvanegmond Posted December 1, 2009 Share Posted December 1, 2009 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. github.com/jvanegmond Link to comment Share on other sites More sharing options...
somdcomputerguy Posted December 1, 2009 Share Posted December 1, 2009 Here is a somewhat sloppy way of doing this in Vista.. Run("control Firewall.cpl") WinWaitActive("Windows Firewall") ConsoleWrite(ControlGetText("Windows Firewall", "", 205) & @CR) WinClose("Windows Firewall") - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Fire Posted December 1, 2009 Share Posted December 1, 2009 ; 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 More sharing options...
MJPollard Posted December 6, 2009 Share Posted December 6, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now