3

I am trying to create a c# form with 2 buttons.

btn1 = disable LAN
btn2 = enable LAN

I have never done something on this level before.

What I want to accomplish is when I click on btn1 I want to disabled the LAN, and btn to enable it again.

This is what I am testing:

System.Diagnostics.Process.Start(ipconfig);

This runs, it runs the cmd and ipconfig I can actually see the IP display BUT...

This is the netsh command:

netsh interface set interface name="Local Area Connection" admin=DISABLED

If I run this via the console it works 100%

I want to use this command by clicking the button?

How do I go about getting this to work? Because I have tried this and does not work:

System.Diagnostics.Process.Start(netsh interface set interface name="Local Area Connection " admin=DISABLED);

any help?

Dariusz Woźniak
  • 9,640
  • 6
  • 60
  • 73
s0mePe0ple
  • 39
  • 2
  • 5

2 Answers2

4

This should work:

System.Diagnostics.Process.Start("netsh.exe", "whatever you would need to write as parameters");

For instance, for a mobile broadband connection, I would start this connection with:

System.Diagnostics.Process.Start("netsh.exe", "mbn connect interface=\"Mobile broadband\" connmode=name name=\"NAME OF CONNECTION\"");

In the above example, you would be able to find the name of the connection by finding the connection in your typical network manager (in Windows 8, it's in the right-side slide-in network overview thing). This part is not really relevant to your question, though, but others might be interested in it.

pravprab
  • 2,301
  • 3
  • 26
  • 43
markj
  • 137
  • 10
0

Try this:

Process.Start("cmd", "/C netsh interface set interface name=\"Local Area Connection\" admin=DISABLED");
Liam
  • 27,717
  • 28
  • 128
  • 190
SoftwareFactor
  • 8,430
  • 3
  • 30
  • 34