Is there a way to block Internet access to my PC by writing code in C#?
I’m using Windows 7, a way to control the firewall will also help. I’ve seen solutions for Windows XP and Windows Vista, but I didn’t find any for ‘7’.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the WMI class
Win32_NetworkAdapterto disable/enable the network adapter.Here’s a link to info about that class:
http://msdn.microsoft.com/en-us/library/aa394216%28v=VS.85%29.aspx
Edit: Due to comment said that you only want to disable incoming traffic.
If you want to disable only incoming traffic I think you might have to use the
Windows Firewall API, I’ve never used it so I’m not sure if it would be able to do that but seems plausible, and it is Win 7 compatible as far as I can tell.Here’s a link to it (I’d suggest the VBscript samples might be easier to translate to C# than the C++ samples):
http://msdn.microsoft.com/en-us/library/aa366453%28v=VS.85%29.aspx