How can I make the following method applies only to one process?
using System.Diagnostics;
using System.IO;
using System.Reflection;
private void button1_Click(object sender, EventArgs e)
{
System.ServiceProcess.ServiceController scPAServ = new System.ServiceProcess.ServiceController("PolicyAgent");
if (scPAServ.Status != System.ServiceProcess.ServiceControllerStatus.Running)
{
scPAServ.Start();
}
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++)
{
ProcessStartInfo psiStart = new ProcessStartInfo();
psiStart.CreateNoWindow = true;
psiStart.FileName = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "\\ipseccmd.exe";
psiStart.Arguments = strCommands[i];
psiStart.WindowStyle = ProcessWindowStyle.Hidden;
Process p = System.Diagnostics.Process.Start(psiStart);
}
}
private void button2_Click(object sender, EventArgs e)
{
System.ServiceProcess.ServiceController scPAServ = new System.ServiceProcess.ServiceController("PolicyAgent");
if (scPAServ.Status != System.ServiceProcess.ServiceControllerStatus.Running)
{
scPAServ.Start();
}
string strCommands = @"-w REG -p ""Firewall"" -r ""Block All"" -f *:*:*+*:*:* -n BLOCK -y";
ProcessStartInfo psiStart = new ProcessStartInfo();
psiStart.CreateNoWindow = true;
psiStart.FileName = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "\\ipseccmd.exe";
psiStart.Arguments = strCommands;
psiStart.WindowStyle = ProcessWindowStyle.Hidden;
Process p = System.Diagnostics.Process.Start(psiStart);
}
}