Code
// Disable setnetworkadapter (false)
// Enable setnetworkadapter (true)
// Add reference system32 \ shell32.dll
Private Static bool setnetworkadapter (bool status ){
Const string discverb = "Disable"; // "Disable (& B )";
Const string connverb = "enable"; // "enable (& )";
Const string network = "Network Connections"; // "network connection ";
Const string networkconnection = "Local Area Connection"; // "Local Connection"
String sverb = NULL;
If (Status ){
Sverb = connverb;
} Else {
Sverb = discverb;
}
Shell32.shell SH = new shell32.shell ();
Shell32.folder folder = Sh. namespace (shell32.shellspecialfolderconstants. ssfcontrols );
Try {
// All options for entering the control panel
Foreach (shell32.folderitem myitem in folder. Items ()){
// Enter the network connection
If (myitem. Name = Network ){
Shell32.folder FD = (shell32.folder) myitem. getfolder;
Foreach (shell32.folderitem fi in FD. Items ()){
// Find the local connection
If (Fi. Name = networkconnection )){
// Find all shortcut menu for local connection
Foreach (shell32.folderitemverb fib in FI. verbs ()){
If (FIB. Name = sverb ){
FIB. doit ();
Return true;
}
}
}
}
}
}
} Catch (exception e ){
Console. writeline (E. Message );
Return false;
}
Return true;
}