Что не так с кодом bat?

GOOS

Новичок
Автор темы
1
0
можете проверить скрипт! правильный ли он?
Bash:
@echo off
cls
chcp 65001 > nul
setlocal EnableDelayedExpansion

REM Check if the script is running with admin privileges
net session >nul 2>&1
if %errorLevel% == 0 (
    goto menu
) else (
    echo This script must be run as an administrator.
    pause
    exit
)

:menu
cls
echo ------------------------------
echo Select an action:
echo 1 - Disable automatic updates
echo 2 - Enable automatic updates
echo 3 - Disable automatic drivers
echo 4 - Enable automatic drivers
echo 5 - Exit
echo ------------------------------
set /p choice=Select an action:

if "!choice!" == "1" (
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoUpdate >nul 2>&1
    if %errorlevel%==0 (
        echo Windows automatic updates are already disabled.
    ) else (
        reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoUpdate /t REG_DWORD /d 1 /f
        echo Windows automatic updates disabled.
    )
    pause>nul
    goto menu
) else if "!choice!" == "2" (
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoUpdate >nul 2>&1
    if %errorlevel%==1 (
        echo Windows automatic updates are already enabled.
    ) else (
        reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoUpdate /t REG_DWORD /d 0 /f
        echo Windows automatic updates enabled.
    )
    pause>nul
    goto menu
) else if "!choice!" == "3" (
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching" /v SearchOrderConfig >nul 2>&1
    if %errorlevel%==0 (
        echo Automatic hardware driver installation is already disabled.
    ) else (
        reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching" /v SearchOrderConfig /t REG_DWORD /d 0 /f
        echo Automatic hardware driver installation disabled.
    )
    pause>nul
    goto menu
) else if "!choice!" == "4" (
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching" /v SearchOrderConfig >nul 2>&1
    if %errorlevel%==1 (
        echo Automatic hardware driver installation is already enabled.
    ) else (
        reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching" /v SearchOrderConfig /t REG_DWORD /d 1 /f
        echo Automatic hardware driver installation enabled.
    )
    pause>nul
    goto menu
) else if "!choice!" == "5" (
    goto end
) else (
    echo Invalid choice, please try again.
    pause>nul
    goto menu
)

:end
echo Exiting the script.
pause>nul
 
Последнее редактирование: