Code to Turn off a firewall

seanvoth

Well-known member
Joined
Aug 5, 2006
Messages
58
Programming Experience
1-3
i have a button and when i click it i want it to turn off a firewall

i also have a button to turn on a firewall

the prob is that i cant figure out the code please help me:eek:
 
Place this code in the Enable button click event handler:
VB.NET:
Dim psi As New ProcessStartInfo("netsh", "firewall set opmode enable")
psi.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(psi)
Same for Disable button, just change 'enable' to 'disable'.

Only works for Windows Firewall..
 
Works here, I even get a balloon warning right away about the protection is off. Maybe you don't have permission? What Windows version are you on? Sure your firewall is the Windows own?
Anyway, since you don't see any error messages with a hidden window that exits right after the command, go to command console and type the command manually: from Start Menu, Run "cmd.exe", in the black box type the command "netsh firewall set opmode disable" and press enter key.
Now, see if it tells you anything.
 
You need administrative rights on the local computer to configure windows Firewall. There may exist numerous other third party firewalls that cannot be controlled programmatically. In a networked/routed environment like usually is at schools/offices the firewall usually in centralized only to be operated by network administrator. In such environment a local Win 2000/2003/XP firewall may still be enabled and can be configured locally, given rights. Windows Firewall does not support any remote configuration.
 
Back
Top