Basically I'm running some performance tests and don't want the external network to be the drag factor. I'm looking into ways of disabling network LAN. What is an effective way of doing it programmatically? I'm interested in c#. If anyone has a code snippet that can drive the point home that would be cool.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
I modfied the best voted solution from Kamrul Hasan to one methode and added to wait for the exit of the process, cause my Unit Test code run faster than the process disable the connection.
For Windows 10 Change this: for diable ("netsh", "interface set interface name=" + interfaceName + " admin=DISABLE") and for enable ("netsh", "interface set interface name=" + interfaceName + " admin=ENABLE") And use the program as Administrator
And use the Program as Administrator !!!!!!
Found this thread while searching for the same thing, so, here is the answer :)
The best method I tested in C# uses WMI.
http://www.codeproject.com/KB/cs/EverythingInWmi02.aspx
Win32_NetworkAdapter on msdn
C# Snippet : (System.Management must be referenced in the solution, and in using declarations)
Using netsh Command, you can enable and disable “Local Area Connection”
In VB.Net , You can also use it for toggle Local Area Connection
Note: myself use it in Windows XP, it's work here properly. but in windows 7 it's not work properly.