Enable or Disable the firewall via Script

Posted by robd on May 15, 2012
Firewall

As per the proxy on & off script, this does the same with Windows Firewall!!

It Enables or Disables the firewall!!  Some users need the firewall on for VPN applications when at home:

Note: This script enables a service so the user will need the relevant permissions!!

On:

 

On Error Resume Next

Set objFwMgr = CreateObject("HNetCfg.FwMgr")
If Err <> 0 Then
  WScript.Echo "Unable to connect to Windows Firewall."
  WScript.Quit
End If

Set objProfile = objFwMgr.LocalPolicy.CurrentProfile

If objProfile.FirewallEnabled = False Then
  WScript.Echo "Windows Firewall is Disabled."

  objProfile.FirewallEnabled = True
  WScript.Echo "Windows Firewall now Enabled."
Else
  WScript.Echo "Windows Firewall already Enabled."
End If

Off:

 

On Error Resume Next

Set objFwMgr = CreateObject("HNetCfg.FwMgr")
If Err <> 0 Then
  WScript.Echo "Unable to connect to Windows Firewall."
  WScript.Quit
End If

Set objProfile = objFwMgr.LocalPolicy.CurrentProfile

If objProfile.FirewallEnabled = True Then
  WScript.Echo "Windows Firewall is enabled."

  objProfile.FirewallEnabled = False
  WScript.Echo "Windows Firewall now disabled."
Else
  WScript.Echo "Windows Firewall already disabled."
End If

Note: Think this script was made by the MS scripting guys!

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.