Description
This batch script will reboot to safe mode if you are in normal (user mode). If executed in safe mode, it will reboot to normal (user mode).
Code:
CLS
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================
:checkPrivileges
echo Y|NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (shift & goto gotPrivileges)
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************
setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
exit /B
:gotPrivileges
setlocal & pushd .
for /f "skip=1 tokens=* delims=" %%a in ('wmic COMPUTERSYSTEM GET BootupState ^| findstr /r /v "^$"') do (set state=%%a)
set state=%state%##
set state=%state: ##=##%
set state=%state: ##=##%
set state=%state: ##=##%
set state=%state: ##=##%
set state=%state: ##=##%
set state=%state:##=%
if "%state%"=="Normal boot" (
bcdedit /set {current} safeboot network
) else (
bcdedit /deletevalue {current} safeboot
)
shutdown -r -t 0
How to use
Copy the code above to a new file and change the extension to .cmd .
Bookmarks