This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

System Information
.NET 1.1+

Detecting Windows Safe Mode

Microsoft Windows can start in a special mode known as "Safe Mode". In this mode, certain drivers are disabled and networking may not be available. If your software requires this missing functionality, problems may occur.

What is Safe Mode?

Microsoft Windows can be started in a special diagnostic mode known as "safe mode". This mode of operation can be entered automatically by Windows following a serious problem, such as a misbehaving hardware driver causing the operating system to crash. It can also be selected manually by the user at start-up if there are known configuration or driver problems that require attention or that are preventing Windows from starting normally.

Safe mode limits the drivers that are loaded to the minimal set required for Windows to operate. This usually means that most peripherals do not function and that the installed video driver is substituted with a simple VGA driver that is supported by all standard graphics cards. This simple configuration makes it possible for the user to remove or replace faulty drivers and reconfigure registry settings that are corrupt or invalid.

If your application requires access to drivers that are not available in safe mode, you should detect the status of Windows before allowing the user to execute your software. If your application requires network access, you should also determine whether the operating system is in normal mode, safe mode or the special safe mode with networking support.

Detecting the Boot Mode

The boot mode of Windows can be determined easily using the SystemInformation class. This class is provided in the System.Windows.Forms namespace of the .NET framework. Within the class is a property called "BootMode" that returns a value of the BootMode enumerated type. This enumeration contains three possible values:

  • Normal. Indicates that the operating system booted normally.
  • FailSafe. Indicates that the operating system is in safe mode with no networking facilities.
  • FailSafeWithNetwork. Indicates that the operating system is in safe mode and that networking support is available.

Example Code

The following code can be added to a Windows application. It detects the current mode and, if it determines that the operating system is not in normal mode, execution is halted.

BootMode mode = SystemInformation.BootMode;

if (mode != BootMode.Normal)
    MessageBox.Show("This program does not operate in safe mode.");
21 July 2008