Detect Directory Services Restore Mode in code
On a Windows domain controller, how can I verify from code that I am running in 'Directory Services Restore Mode'?
I need开发者_StackOverflow社区 to do this from either Java, C or C++ but other code samples are welcome.
Invoke the Win API function GetSystemMetrics(SM_CLEANBOOT). It gives an int result which can then be interpreted as follows:
- 0 = Running in Normal Mode
- 1 = Running in Safe Mode
- 2 = Running in Safe Mode with Networking
- 3 = Running in Directory Services Restore Mode
An alternative is to inspect the registry at:
HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Option\OptionValue
When booting in Safe Mode, this registry key (which doesn't exist when booted normally) will contain a DWORD value that corresponds to the above values.
If the option value is 1 then only services and drivers specified under
HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Minimal
will be loaded. Likewise if the value is 2 then only services and drivers specified under
HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network
will be loaded
精彩评论