From b4396973cbd589d4dd1adb2a4c8790bb1c158950 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Wed, 10 Nov 2021 20:18:27 -0500 Subject: [PATCH] add Fix-RebootIntoSafeMode.ps1 --- Fix-RebootIntoSafeMode.bat | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Fix-RebootIntoSafeMode.bat diff --git a/Fix-RebootIntoSafeMode.bat b/Fix-RebootIntoSafeMode.bat new file mode 100644 index 0000000..51b66c9 --- /dev/null +++ b/Fix-RebootIntoSafeMode.bat @@ -0,0 +1,60 @@ +@echo off +setlocal enabledelayedexpansion +cls + +rem Temporary file to store the services we'll need to enable +set FILENAME=safebootservices.txt + +rem List of services that need to be started in Safe Mode with Networking +echo AteraAgent> %FILENAME% +echo Splashtop Inc.>> %FILENAME% +echo SplashtopRemoteService>> %FILENAME% + +echo. +echo Configuring required services to automatically start in Safe Mode with Networking +set /a REBOOT=0 + +for /f "delims=" %%G in (%FILENAME%) do ( + set SERVICE=%%G + call :reset-errorlevel + reg add "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\!SERVICE!" /f > nul 2>&1 + if !ERRORLEVEL! GTR 0 ( + echo ERROR: could not configure "!SERVICE!" service to start in Safe Mode with Networking + set /a REBOOT=!REBOOT!+1 + ) +) + +call :reset-errorlevel +reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce" /v "*RestartNormalMode" /t REG_SZ /d "%SystemRoot%\System32\bcdedit.exe /deletevalue {current} safeboot" /f > nul 2>&1 +if %ERRORLEVEL% GTR 0 ( + echo ERROR: could not configure reboot into normal mode + set /a REBOOT=%REBOOT%+1 +) + +if %REBOOT% EQU 0 goto :reboot +goto :end-error + +:reboot +call :reset-errorlevel +"%SystemRoot%\System32\bcdedit.exe" /set {current} safeboot network +if %ERRORLEVEL% EQU 0 ( + shutdown /r /f /t 10 + echo Restarting in 10 seconds + goto :end +) else ( + echo ERROR: could not restart in Safe Mode with Networking + goto :end-error +) + +:end-error +echo. +echo Errors were encountered and the system will not be restarted +echo Please make sure this script is run with administrative privileges +goto :end + +:end +del /f %FILENAME% +goto :EOF + +:reset-errorlevel +cmd /c "exit /b 0" \ No newline at end of file