1) first remember to add "app.manifest"(Project menu->Add New Item->Application Manifest file) in project and
2) add
<requestedexecutionlevel level="requireAdministrator" uiaccess="false" />
before "
</requestedPrivileges>
" tag.
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
3)
now in .cs file
4) add library file
using System.Diagnostics;
5) enable firewall of system
private void btnfire_Click(object sender, EventArgs e)
{
try
{
Process proc = new Process();
string top = "netsh.exe";
proc.StartInfo.Arguments = "Firewall set opmode enable";
proc.StartInfo.FileName = top;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
MessageBox.Show("Enable");
}
catch (Exception ex)
{
MessageBox.Show("Error");
}
}
6)disable firewall of system
private void button5_Click(object sender, EventArgs e)
{
try
{
Process proc = new Process();
string top = "netsh.exe";
proc.StartInfo.Arguments = "Firewall set opmode disable";
proc.StartInfo.FileName = top;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
MessageBox.Show("Disable");
}
catch (Exception ex)
{
MessageBox.Show("Error");
}
}
"