Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / MFC
Article

How to enable and disable Windows XP SP2 firewall, programmatically

Rate me:
Please Sign up or sign in to vote.
2.63/5 (19 votes)
18 Jan 20051 min read 176.3K   2.6K   30   10
How to programmatically enable and disable Windows XP SP2 firewall.

Introduction

Since the birth of Windows XP, Microsoft is more proud of its OS. XP is really a robust operating system. After service pack 2 of this product, Microsoft introduced a very good thing called Security Center to increase user security, providing firewall, popup blocker, and etc. All these are very useful to all users. For example, firewall can prevent other applications accessing services like FTP service without permission from users. To access firewall, you can use Firewall’s API, but for those that would like to just enable/disable XP’s firewall.

I wrote an application (with just a few lines of code) to do it!!!

Let’s see how a firewall acts in a system: when user selects “turn on” or “turn off”, it saves information as 1 or 0 in the Registry, under this key:

HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\ 
                            Parameters\FirewallPolicy\StandardProfile

With a REG_DWORD value named EnableFirewall, 0 means turn off and 1 means turn on! But at this time, if you select “turn off” in Security Center, you will be informed by a red notify icon and balloon text that appears in system, trying to give you this message:

This is because at this time, SVCHOST.EXE, after this change in Registry, will load another application named “wscntfy.exe” belonging to XP SP2, in the system root %system32%. And wscntfy.exe notifies users by this message!!!

If you run your own application changing the EnableFirewall value in Registry, then renaming your application file as “wscntfy.exe”, you have successfully disabled the firewall and users will know nothing about it!!!

I tested my application in latest SP2 updated from Microsoft. My source code is in MFC, a very small application.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
France France
Khosrov Boloorian is working in Windows system programming, driver and kernel module development

Comments and Discussions

 
GeneralMy vote of 3 Pin
Mahdi Nejadsahebi17-Feb-12 20:00
Mahdi Nejadsahebi17-Feb-12 20:00 
Generalgood Pin
Donsw18-Sep-09 6:57
Donsw18-Sep-09 6:57 
Generalbatch file is very nice Pin
jhaverimehul3-Feb-07 1:38
jhaverimehul3-Feb-07 1:38 
QuestionRegistry may vary! Pin
leojose3-Feb-06 22:54
leojose3-Feb-06 22:54 
Generalhelp Pin
gtraiden5-Oct-05 22:00
gtraiden5-Oct-05 22:00 
GeneralBatch Script Pin
Anonymous25-Apr-05 16:31
Anonymous25-Apr-05 16:31 
QuestionHow to open a port or grant rights to an executable programatically? Pin
Carl Mercier18-Jan-05 5:46
Carl Mercier18-Jan-05 5:46 
AnswerRe: How to open a port or grant rights to an executable programatically? Pin
Dennis C. Dietrich18-Jan-05 6:09
Dennis C. Dietrich18-Jan-05 6:09 
GeneralThis is not a bug Pin
Dennis C. Dietrich18-Jan-05 4:26
Dennis C. Dietrich18-Jan-05 4:26 
GeneralRe: This is not a bug Pin
Anonymous20-May-05 7:26
Anonymous20-May-05 7:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.