Internet connection can be disconnected by unplugging the network cable.

How could i do this through c# program.

And again i need to connect to the internet connection after a while.

My system is connected with LAN, i should disconnect only my system from the internet.

Can anyone help me please??

link|improve this question
Which operating system? – grawity May 17 '11 at 4:45
3  
I thought I've seen this before: superuser.com/questions/284175/… – slhck May 17 '11 at 5:06
@grawity: Windows XP – sam May 17 '11 at 6:37
Please clarify, do you want your PC to remain on the LAN but have no internet access, or do you want to disconnect from the LAN? – Tog May 17 '11 at 8:19
@slhck - just seen your link... kinda regret actually providing an answer now. Been asked at least twice here, and once on SO - not once in a coherent way. Although this one does seem to be the clearest so far... – Jaymz May 17 '11 at 9:49
show 1 more comment
feedback

closed as off topic by slhck, DMA57361 May 17 '11 at 9:52

Questions on Super User are expected to generally relate to computer software or computer hardware, within the scope defined in the faq.

1 Answer

You can disable/enable your NIC from the command line:

netsh interface set interface “Local Area Connection” disabled
netsh interface set interface “Local Area Connection” enabled

Replace "Local Area Connection" with the name of the Network Interface you want to disable.

You can call this from C# using something like the following:

Enable

static void Enable(string interfaceName)
{
    System.Diagnostics.ProcessStartInfo psi = 
        new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface \"" + interfaceName + "\" enable");
    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo = psi;
    p.Start();
}

Disable

static void Disable(string interfaceName)
{
    System.Diagnostics.ProcessStartInfo psi = 
        new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface \"" + interfaceName + "\" disable");
    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo = psi;
    p.Start();
}
link|improve this answer
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.