Microsoft Knowledge Base Email Alertz

(837643) - Describes how to determine whether the system is running in Safe Mode from a device driver. Provides instructions for function drivers, filter drivers, and other drivers.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 837643 - Last Review: May 29, 2004 - Revision: 1.0

How to determine whether the system is running in Safe Mode from a device driver

SUMMARY

This article describes how to determine whether the system is running in Safe Mode from a device driver.

MORE INFORMATION

The Windows OS kernel exports a pointer to a ULONG variable that is named InitSafeBootMode. This variable contains the Safe Mode settings.

A device driver can determine whether the system is running in Safe Mode by the value of the InitSafeBootMode variable. A value of 0 means that the system is not running in Safe Mode.

The following table lists the modes for other values.
Collapse this tableExpand this table
Value Mode
1 SAFEBOOT_MINIMAL
2 SAFEBOOT_NETWORK
3* SAFEBOOT_DSREPAIR
*Note The value of 3 applies to Windows domain controllers only.

You must declare the following in your driver.
extern PULONG InitSafeBootMode; 
You must check the value of InitSafeBootMode to determine whether the system is running in Safe Mode.
if (*InitSafeBootMode > 0){ 

     // The system is in Safe Mode. 
     // Take appropriate action. 
     //     
} 
For example, to prevent a driver from working in Safe Mode, use one of the following methods:
  • Function drivers

    If your function driver has a service start type of SERVICE_BOOT_START, check the value of the InitSafeBootMode variable in the AddDevice routine and return failure.

    Note You must never return failure from the DriverEntry routine.
  • Filter drivers

    If your filter driver starts during boot time, check the value of the InitSafeBootMode variable in the AddDevice routine. Do not attach to the device stack. Return success from the AddDevice routine.
  • Other drivers

    For drivers that are not mentioned earlier, check the value of the InitSafeBootMode variable in the DriverEntry routine. Return failure if the system is in Safe Mode.

APPLIES TO
  • Microsoft Windows Server 2003 Driver Development Kit
  • Microsoft Windows XP Driver Development Kit
  • Microsoft Win32 Device Driver Kit for Windows 2000
Keywords: 
kbinfo kbwdm kbhardware kbddk kbdriver kbdev KB837643
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate