Windows – How to tell if Windows is running in Safe Mode

command-line-interfacenagioswindowswindows-server-2003

I have a Windows server that will sometimes reboot into safe mode after updates. I'm working on that issue but what I'd really like to know is how can I check to see if Windows is running in safe mode or not.

Ideally I would like to incorporate it into a script that would send a passive check to our Nagios box with the status.

Is there some environmental variable I can use or some way to get this information via the command line?

Best Answer

I think this does what you are looking for

PS C:\> gwmi win32_computersystem | select BootupState

BootupState
-----------
Normal boot

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394102%28v=vs.85%29.aspx

Possible return values:

Normal boot
Fail-safe boot
Fail-safe with network boot