OS: Win 7 I googled a lot and I found one answer here which not helping me as it outputs just the answer (I cannot used it in IF statement
I have also found this
if /i "%SAFEBOOT_OPTION%"=="MINIMAL" echo We're in Safe Mode!
I have tried it almost 10 times and the SAFEBOOT_OPTION variable is always empty.
The %SAFEBOOT_OPTION%
variable only exists if you are currently booted into safe mode
(contains MINIMAL
) or safe mode with networking
(contains NETWORK
).
From Microsoft's Docs:
An environment variable is set when you use one of the Safe Boot options. The environment variable is SAFEBOOT_OPTION. This variable is set to either Network or to Minimal.
EDIT
Just tested the script below while running in safe mode:
@echo off
if /i "%SAFEBOOT_OPTION%"=="MINIMAL" echo We're in Safe Mode!
This script printed We're in Safe Mode!
to cmd as expected.