C # Use shell32 to control local connections

Source: Internet
Author: User

 

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;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.