Use C ++ Builder to detect Windows Startup Mode

Source: Internet
Author: User
Use C ++ Builder to check the Windows Startup Mode-general Linux technology-Linux programming and kernel information. The following is a detailed description. Windows 95/98 can be started in normal and secure modes. In secure mode, many functions are restricted to use, such as multimedia and network functions. Sometimes, the program we write requires these restricted functions, so we want to automatically check whether the Startup Mode of the current Windows is safe when the program runs to determine whether to continue running the program.

In the C ++ Builder program, how does one check whether Windows is started in normal or safe mode? This requires using the API function GetSystemMetrics for detection. The API function GetSystemMetrics can obtain some configuration information about Windows, such as the number of mouse buttons and the Border width of the form. It can also measure the Startup Mode of Windows.

In Windows API, the function is defined as follows:

Int GetSystemMetrics (int nIndex );

Among them, the nIndex parameter has many values. If you only want to check the Windows startup mode, you only need to take the parameter value SM_CLEANBOOT. This value confirms the mode in which the current Windows is started. It returns three values:

0: normal start mode;
1. Start Windows in safe mode;
2: It is started in safe mode, but it has network functions.

We can use this function in the starting part of the program. In the following example, the application displays different prompts Based on the Windows Startup Mode, you can add new processing code in actual programming.



Void _ fastcall TForm1: Button1Click (TObject * Sender)

{

Switch (GetSystemMetrics (SM_CLEANBOOT ))

{

Case 0:

ShowMessage ("start in normal mode ");

Break;

Case 1:

ShowMessage ("start in security mode ");

Break;

Case 2:

ShowMessage ("security mode enabled, but with network features ");

Break;

Default:

ShowMessage ("error, system startup error. ");

Break;

}

}
Related Article

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.