Using C++builder to detect Windows Startup mode

Source: Internet
Author: User

Windows 95/98 boot mode can be divided into normal mode and safe mode, in Safe mode, there are many functions are limited to use, such as multimedia functions, network functions. Sometimes, the programs we write just need these limited features, so we want to automatically detect if the current Windows startup mode is safe Mode when the program is running to determine whether to continue running the program.

So how do you detect if the current Windows is started in normal or safe mode in a C + + Builder program? This requires the use of the API function GetSystemMetrics to detect. API function GetSystemMetrics can get some configuration information about Windows, such as the number of mouse keys, the width of the border of the form, it can also measure the current Windows in the boot mode.

In the Windows API, the function is defined as follows:

int getsystemmetrics (int nindex);

There are a lot of values for parameter nindex, and if you want to detect only the startup mode of Windows, the value will confirm the mode in which the current Windows started, as long as the parameter value is sm_cleanboot. It has a return value of three:

0: normal start-up mode;

1: Safe mode to start Windows;

2: Start in safe mode, but have network function.

We can use this function at the beginning of the program, as in the following example, the application displays different prompts depending on the Windows startup mode, and the user can add new processing code specifically in actual programming.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  switch(GetSystemMetrics(SM_CLEANBOOT))
  {
   case 0:
    ShowMessage("正常模式启动");
    break;
   case 1:
    ShowMessage("安全模式启动");
    break;
   case 2:
    ShowMessage("安全模式启动,但带网络附带功能");
    break;
   default:
    ShowMessage("错误,系统启动有问题。");
    break;
  }
}

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.