+ Reply to Thread
Results 1 to 1 of 1

Thread: Script: Reboot Windows to SafeMode

  1. #1

    Script: Reboot Windows to SafeMode

    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 .
    Last edited by Master Razor; 01.08.16 at 10:52.
    Reply With QuoteReply With Quote
    Thanks

  2. Who Said Thanks:

    Codec (07.08.16) , anon (01.08.16)

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •