如何使用Windows脚本以安全模式重新启动计算机



大多数新手计算机用户都会遇到问题并必须重新启动计算机进入安全模式,因此如何脚本将其自动脚本?

这是一个批处理脚本,将重新启动Windows XP,Vista或Windows 7计算机进入安全模式。

Echo Off
REM Check Windows Version
ver | findstr /i "5.0." > nul
IF %ERRORLEVEL% EQU 0 goto ver_nt5x
ver | findstr /i "5.1." > nul
IF %ERRORLEVEL% EQU 0 goto ver_nt5x
ver | findstr /i "5.2." > nul
IF %ERRORLEVEL% EQU 0 goto ver_nt5x
ver | findstr /i "6.0." > nul
IF %ERRORLEVEL% EQU 0 goto ver_nt6x
ver | findstr /i "6.1." > nul
IF %ERRORLEVEL% EQU 0 goto ver_nt6x
goto warn_and_exit
:ver_nt5x
:Run Windows 2000/XP specific commands here
bootcfg /raw /a /safeboot:network /id 1
REG ADD HKLMSOFTWAREMicrosoftWindowsCurrentVersionRunOnce /v "*UndoSB" /t REG_SZ /d "bootcfg /raw /fastdetect /id 1"
SHUTDOWN -r -f -t 07
goto end
:ver_nt6x
:Run Windows Vista/7 specific commands here
bcdedit /set {current} safeboot network
REG ADD HKLMSOFTWAREMicrosoftWindowsCurrentVersionRunOnce /v "*UndoSB" /t REG_SZ /d "bcdedit /deletevalue {current} safeboot"
SHUTDOWN -r -f -t 07
goto end
Echo On
:warn_and_exit
echo Machine OS cannot be determined.
:end 

此脚本最初由Chunkdog发布:

我已经对其进行了修改,并添加了一个vbScript,询问用户是否想重新启动安全模式,并根据用户输入,调用批处理文件。

Dim oShell, returnCode
Set objShell = CreateObject("Shell.Application")
Set oShell = WScript.CreateObject("WScript.Shell")
returnCode = oShell.Popup("Do you want to restart your computer in Safe Mode", 0, "Restart In Safe Mode", 4 + 48 + 256)
Select Case returnCode
case 6, -1
    objShell.ShellExecute "tryout.bat", "", "", "runas", 0
    case 7
    oShell.popup "Operation Canceled", 0, "Restart In Safe Mode", 0 + 64 + 0
End Select

尚未在Windows 8上进行测试。

打开CMD作为admin,然后使用这些参数运行BSDEDIT" bcdedit/set {当前}安全启动网络"

最新更新