Firewall – script to disable windows firewall under Vista

firewallvbscript

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
objPolicy.FirewallEnabled = FALSE

This script does not work in Vista/2008 and Windows 7 anymore.
Even with elevation.

The error box is shown "a program or firewall is not compatible with this version of windows"

Best Answer

For a simple command line \ batch file:

netsh firewall set opmode disable

Or with PowerShell:

$firewall = New-Object -com HNetCfg.FwMgr
$firewall.LocalPolicy.CurrentProfile.FirewallEnabled = $false

Both work fine under Windows Vista. If you are still having issues then I'd dig further to ensure that you have the right permissions and that you are using core windows components to execute the script. I have a parallel install of PowerShell (used by the VMWare VI Toolkit) that throws exactly the same security exception you list above when I try to use it to disable the firewall but for the basic Powershell v1.0 installation it works fine.