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 operates in safe mode.");
Application.Exit();
}
No comments:
Post a Comment