Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi How to cut a growing process of Internet access?
I want to block Internet just for a process, Not block all Internet buffer.
what?
Posted
Updated 29-Oct-13 6:56am
v3
Comments
Valery Possoz 29-Oct-13 11:40am    
It's not really a programming question...
A way to do it is to configure your firewall for example: http://www.trishtech.com/2010/05/block-a-program-in-windows-7-firewall/
payam1485 29-Oct-13 11:50am    
You see my friend I know who gets the firewall configuration but would like to do this with C#.
what?
ZurdoDev 29-Oct-13 12:00pm    
What?

Here there's an answer which can put you on the right road:
Any way to turn the “internet off” in windows using c#?[^]
 
Share this answer
 
Comments
payam1485 29-Oct-13 12:16pm    
OK my friend
But I don't want to block all Internet buffer. I want to cut a one program access to the Internet and connect again if need be.
phil.o 29-Oct-13 12:45pm    
Did you just read the title and declared it wasn't worth the look, or did you actually go and see the example?
Because given example shows how to manipulate Windows Firewall; explore the INetFwRule class, I'm sure it holds something valuable for you...
payam1485 29-Oct-13 13:01pm    
Yes you are correct please but I have nothing like that on all of the Windows give this answer is only for Windows 7.
anyway thanks you so made up of am and I'll beg if you can help me because I need so much.
Thank you
How can I make the following method applies only to one process?

C#
using System.Diagnostics;
using System.IO;
using System.Reflection;

private void button1_Click(object sender, EventArgs e)
{
//ADDED A REFERENCE TO SYSTEM.SERVICEPROCESS VIA PROJECT->ADD REFERENCE, .NET tab
System.ServiceProcess.ServiceController scPAServ = new System.ServiceProcess.ServiceController("PolicyAgent"); //IPSec

if (scPAServ.Status != System.ServiceProcess.ServiceControllerStatus.Running)
{
scPAServ.Start(); //Start If Not Running
}
string[] strCommands =  { 
@"-w REG -p ""Firewall"" -r ""Block All"" -f *:*:*+*:*:* -n BLOCK -x" ,
@"-w REG -p ""Firewall"" -r ""Allow LAN"" -f 0:*:*+192.168.10.*:*:* -n PASS -x" ,
@"-w REG -p ""Firewall"" -r ""DNS"" -f 0:*:UDP+223.211.190.23:53:UDP 0:*:UDP+223.211.190.24:53:UDP 0:*:TCP+223.211.190.23:53:TCP
0:*:TCP+223.211.190.24:53:TCP -n PASS -x" , 
@"-w REG -p ""Firewall"" -r ""POP3"" -f 0:*:TCP+*:110:TCP -n PASS -x" ,
@"-w REG -p ""Firewall"" -r ""POP3S"" -f 0:*:TCP+*:995:TCP -n PASS -x" ,
@"-w REG -p ""Firewall"" -r ""FTP Control"" -f 0:*:TCP+*:21:TCP -n PASS -x" ,
@"-w REG -p ""Firewall"" -r ""FTP Data"" -f 0:*:TCP+*:20:TCP -n PASS -x" ,
@"-w REG -p ""Firewall"" -r ""IMAP"" -f 0:*:TCP+*:143:TCP -n PASS -x" ,
@"-w REG -p ""Firewall"" -r ""HTTP"" -f 0:*:TCP+*:80:TCP -n PASS -x" ,
@"-w REG -p ""Firewall"" -r ""HTTPS"" -f 0:*:TCP+*:443:TCP -n BLOCK -x" ,
@"-w REG -p ""Firewall"" -r ""PROXY"" -f 0:*:TCP+*:8080:TCP 0:*:TCP+*:3128:TCP 0:*:TCP+*:8081:*:TCP 0:*:TCP+*:8000:TCP -n BLOCK -x"};

for (int i = 0; i < strCommands.Length; i++) //Loop through each Command String
{
ProcessStartInfo psiStart = new ProcessStartInfo(); //Process To Start

psiStart.CreateNoWindow = true; //Invisible

psiStart.FileName = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "\\ipseccmd.exe"; //IPSEC

psiStart.Arguments = strCommands[i]; //Break Command Strings Apart

psiStart.WindowStyle = ProcessWindowStyle.Hidden; //Invisible

Process p = System.Diagnostics.Process.Start(psiStart); //Start Process To Block Internet Connection
}
}

private void button2_Click(object sender, EventArgs e)
{
System.ServiceProcess.ServiceController scPAServ = new System.ServiceProcess.ServiceController("PolicyAgent"); //IPSec

if (scPAServ.Status != System.ServiceProcess.ServiceControllerStatus.Running) //If Not Running
{
scPAServ.Start(); 
}
string strCommands = @"-w REG -p ""Firewall"" -r ""Block All"" -f *:*:*+*:*:* -n BLOCK -y"; //Commands To Send

ProcessStartInfo psiStart = new ProcessStartInfo(); //Process To Start

psiStart.CreateNoWindow = true; //Invisible

psiStart.FileName = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "\\ipseccmd.exe"; //IPSEC

psiStart.Arguments = strCommands; //Give Command String As Argument

psiStart.WindowStyle = ProcessWindowStyle.Hidden;  //Invisible

Process p = System.Diagnostics.Process.Start(psiStart);  //Start Process To Stop Internet Connection
}
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900