C # Call Control Panel options

Source: Internet
Author: User
In Windows, the control panel file is generally suffixed with ". Cpl". The following table lists the common options and file names of the Windows Control Panel:

Bytes -------------------------------------------------------------------------------------------------

Option file name

Bytes --------------------------------------------------------------------------------------------------

Internet option: inetcpl. CPL

ODBC Data Source Management: odbccp32.cpl

Telephone and modem options: telephon. CPL

Power option: powercfg. CPL

Auxiliary Function options: Access. CPL

Region and language options: intl. CPL

Date and Time: TimeDate. CPL

Sound and audio devices: mmsys. CPL

Mouse: Main. CPL

Add or deleteProgram: Appwiz. CPL

Add hardware: hdwwiz. CPL

Network Connection: NCPA. CPL

System: sysdm. CPL

Display: desk. CPL

User Account: nusrmgr. CPL

Game Controller: Joy. CPL

Voice: SAPI. CPL

Bytes ----------------------------------------------------------------------------------------------------

Fonts

Bytes ----------------------------------------------------------------------------------------------------

These are common options in the control panel.

Operation:

In C #, you can use the following methods:

Using system. diagnostics; // called when the namespace is called.

// We can use the following method in event processing:

Try

{

Process. Start ("[with the full name of the above file name]");

}

Catch (win32exception win32ex)

{

MessageBox. Show ("error cause:" + win32ex. message, "error", messageboxbuttons. OK, messageboxicon. Error );

}

Example:

Take Internet options as an example:

Let's modify the aboveCodeIs:

Using system. diagnostics;

Processstartinfo info = new processstartinfo ();

Try

{

Info. filename = "inetcpl. Cpl ";

Process. Start (Info );

}

Catch (win32exception win32ex)

{

MessageBox. Show ("error cause:" + win32ex. message, "error", messageboxbuttons. OK, messageboxicon. Error );

}

After running the program, the following results are displayed:

If we do not enter the complete file name in the program, an error will be generated with the following prompt:

AppendixSource code:

Using system;

Using system. drawing;

Using system. collections;

Using system. componentmodel;

Using system. Windows. forms;

Using system. Data;

Using system. diagnostics;

Namespace csharpcallcpl

{

/// <Summary>

/// Summary of form1.

/// </Summary>

Public class form1: system. Windows. Forms. Form

{

Private system. Windows. Forms. Button button1;

Private system. Windows. Forms. Label label1;

/// <Summary>

/// Required designer variables.

/// </Summary>

Private system. componentmodel. Container components = NULL;

Public form1 ()

{

//

// Required for Windows Form Designer support

//

Initializecomponent ();

//

// Todo: add Any constructor code after initializecomponent calls

//

}

/// <Summary>

/// Clear all resources in use.

/// </Summary>

Protected override void dispose (bool disposing)

{

If (disposing)

{

If (components! = NULL)

{

Components. Dispose ();

}

}

Base. Dispose (disposing );

}

# Region windows Form Designer generated code

/// <Summary>

/// The designer supports the required methods-do not use the code editor to modify

/// Content of this method.

/// </Summary>

Private void initializecomponent ()

{

This. button1 = new system. Windows. Forms. Button ();

This. label1 = new system. Windows. Forms. Label ();

This. suspendlayout ();

//

// Button1

//

This. button1.location = new system. Drawing. Point (192, 72 );

This. button1.name = "button1 ";

This. button1.tabindex = 0;

This. button1.text = "call ";

This. button1.click + = new system. eventhandler (this. button#click );

//

// Label1

//

This. label1.autosize = true;

This. label1.font = new system. drawing. font ("", 15.75f, system. drawing. fontstyle. bold, system. drawing. graphicsunit. point, (system. byte) (134 )));

This. label1.location = new system. Drawing. Point (40, 16 );

This. label1.name = "label1 ";

This. label1.size = new system. Drawing. Size (203, 24 );

This. label1.tabindex = 1;

This. label1.text = "C # Call Control Panel example ";

//

// Form1

//

This. autoscalebasesize = new system. Drawing. Size (6, 14 );

This. clientsize = new system. Drawing. Size (296,125 );

This. Controls. addrange (new system. Windows. Forms. Control [] {

This. label1,

This. button1 });

This. Name = "form1 ";

This. Text = "form1 ";

This. resumelayout (false );

}

# Endregion

/// <Summary>

/// Main entry point of the application.

/// </Summary>

[Stathread]

Static void main ()

{

Application. Run (New form1 ());

}

Private void button#click (Object sender, system. eventargs E)

{

Processstartinfo info = new processstartinfo ();

Try

{

Info. filename = "inetcpl. Cpl ";

Process. Start (Info );

}

Catch (win32exception win32ex)

{

MessageBox. Show ("error cause:" + win32ex. message, "error", messageboxbuttons. OK, messageboxicon. Error );

}

}

}

}

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.