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 intosafe mode(containsMINIMAL) orsafe mode with networking(containsNETWORK).From Microsoft's Docs:
EDIT
Just tested the script below while running in safe mode:
This script printed
We're in Safe Mode!to cmd as expected.