Vbscript 如何使用Windows脚本在安全模式下重新启动计算机?

Vbscript 如何使用Windows脚本在安全模式下重新启动计算机?,vbscript,batch-file,restart,safe-mode,Vbscript,Batch File,Restart,Safe Mode,大多数计算机新手在遇到问题时都会感到困惑,必须将计算机重新启动到安全模式,那么如何编写脚本使其自动运行呢?下面是一个批处理脚本,可以将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

大多数计算机新手在遇到问题时都会感到困惑,必须将计算机重新启动到安全模式,那么如何编写脚本使其自动运行呢?

下面是一个批处理脚本,可以将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 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /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 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /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,然后使用这些参数运行bsdedit
“bcdedit/set{current}safeboot network”

嗨,詹姆斯,很高兴看到你为自己的问题给出了一个很好的答案。将来,当您创建问题时,您可以选中“回答我自己的问题”复选框,这将允许您在发布之前写下答案,并且有人有机会关闭它:)