为什么进入主菜单后选择选项一回车就闪退啊?

为什么进入主菜单后选择选项一回车就闪退啊?

title 密码验证
@echo off
cls

:: 检查管理员权限
echo 正在检查管理员权限......
NET SESSION >nul 2>&1
if %errorLevel% == 0 (
    :: 已经是管理员,继续执行脚本
    goto :ELEVATED
) else (
    :: 请求提升为管理员权限
    echo 正在提升管理员权限......
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B
)

:ELEVATED
:: 以下是已经以管理员权限运行的代码
echo 已确认为管理员权限。
cls

:: 延迟环境变量
echo 正在设置延迟环境变量......
setlocal enabledelayedexpansion
cls

:: 设置密码文件路径
echo 正在设置依赖文件路径......
set password_file=C:\Windows\password.pfx
set hash_password_file=C:\Windows\hash_password.pfx
set input_file=C:\Windows\input.pfx
set hash_input_file=C:\Windows\hash_input.pfx
cls

:: 设置初始密码(不要设置为敏感密码,初始密码会被公开)
echo 正在读取初始密码......
set initial_password=000000
cls

:: 设置盐值(参与加密计算,增大密码破解难度)
echo 正在读取盐值......
set salt=3.14159265358979323846264338327950288419716939937510
cls

:: 检查密码文件是否存在,若不存在则创建文件并设置默认密码
if not exist "%hash_password_file%" (
    del "%password_file%"
    cls
    echo 正在配置初始密码......
    echo %initial_password%>"%password_file%"
    echo 正在加密初始密码......
    powershell -command "$sha512 = [System.Security.Cryptography.SHA512]::Create(); $saltBytes = [System.Text.Encoding]::UTF8.GetBytes('%salt%'); $sourceBytes = [System.IO.File]::ReadAllBytes('%password_file%'); $saltedBytes = $sourceBytes + $saltBytes; $hashBytes = $sha512.ComputeHash($saltedBytes); $hashString = [System.BitConverter]::ToString($hashBytes).Replace('-', '').ToLower(); [System.IO.File]::WriteAllText('%hash_password_file%', $hashString)"
    echo 正在清理缓存......
    del "%password_file%"
    cls
)

:: 从密码文件读取密码
echo 正在读取密码......
set /p hash_password=<"%hash_password_file%"
cls

:START
echo 请输入密码:
set /p input=
cls
echo 正在验证......
echo !input!>"!input_file!"
powershell -command "$sha512 = [System.Security.Cryptography.SHA512]::Create(); $saltBytes = [System.Text.Encoding]::UTF8.GetBytes('%salt%'); $sourceBytes = [System.IO.File]::ReadAllBytes('!input_file!'); $saltedBytes = $sourceBytes + $saltBytes; $hashBytes = $sha512.ComputeHash($saltedBytes); $hashString = [System.BitConverter]::ToString($hashBytes).Replace('-', '').ToLower(); [System.IO.File]::WriteAllText('!hash_input_file!', $hashString)"
echo 正在清理缓存......
del "!input_file!"
set /p hash_input=<"!hash_input_file!"
del "!hash_input_file!"
echo 验证完成。
if "!hash_input!"=="!hash_password!" (
    color 2F
    cls
    echo 密码正确,即将进入主菜单。
    ping 127.0.0.1 -n 5 >nul
    goto MENU
) else if "!input!"=="3.14159265358979323846264338327950288419716939937510" (
    color E0
    cls
    :: 输入管理员密码,重置密码文件
    if exist "%hash_password_file%" (
        echo 正在重置......
        del "%hash_password_file%"
    ) else (
        color CF
        echo 错误:无法重置密码,未找到密码文件。
        pause
        cls
        goto :ELEVATED
    )
    echo 密码已重置。
    pause
    color 07
    cls
    goto :ELEVATED
) else (
    color CF
    cls
    echo 密码错误,请重新输入(默认密码为:!initial_password!)。
    goto START
)

:MENU
title 主菜单
color F0
cls
echo 1. 自动关机程序
echo 2. 自动静音
echo 3. 修改密码
echo 4. 查看作者
echo 0. 退出程序
echo *输入选项前面的数字即可(不带点)。

set /p choice=请输入选项:

if !choice! == 1 (
    title 自动关机程序——高远原创
    echo 提示:您将更改自动关机选项,确定将关机时间更改为21:40吗?是Y否N(首次设置将自动创建,所有定时需要在“中午注销”设置完后才可删除。)
    pause
    schtasks /create /tn "关机" /tr "shutdown /f /p" /sc daily /st 21:40
    pause
    echo 提示:您将更改自动关机选项,确定将关机时间更改为20:45吗?是YN
    pause
    schtasks /create /tn "关机" /tr "shutdown /f /p" /sc daily /st 20:45
    pause
    echo 提示:您将更改自动关机选项,确定将关机时间更改为17:15吗?是Y否N
    pause
    schtasks /create /tn "关机" /tr "shutdown /f /p" /sc daily /st 17:15
    pause
    echo 提示:您将自定义自动关机时间,请输入关机时间,格式为XX:XX(小时仅一位数时,格式为0X:XX),半角符号,之后确定Y取消N;若不设置,请按三次回车
    echo 请输入关机时间:(XX:XX0X:XXset/p A=
    echo 提示:确定将关机时间更改为!A!吗?是Y否N
    pause
    schtasks /create /tn "关机" /tr "shutdown /f /p" /sc daily /st !A!
    pause
    echo 提示:是否设置每天中午12:20自动注销?是YN(首次设置将自动创建,所有定时需要在当前任务设置完后才可删除。)
    if /I !choice! == Y (
        schtasks /create /tn "中午注销" /tr "shutdown /f" /sc daily /st 12:20
        pause
    )
    color E0
    echo 重要提示:您将取消所有自动关机、注销任务,确定继续吗?是YN
    set /p choice=请输入选项:
    if /I !choice! == Y (
        color CF
        echo 警告:您将取消所有自动关机、注销任务(需要确认),这是最后一次提示,确定继续吗?删除Y保留N
        pause
        schtasks /delete /tn "中午注销"
        schtasks /delete /tn "关机"
    )
    color 2F
    echo 提示:完成!
    pause
    cls
    goto MENU
) else if !choice! == 2 (
    title 自动静音
    schtasks /create /sc daily /tn "取消静音1" /tr "net start AudioSrv" /st 07:55 /ru SYSTEM
    schtasks /create /sc daily /tn "静音1" /tr "net stop AudioSrv" /st 12:10 /ru SYSTEM
    schtasks /create /sc daily /tn "取消静音2" /tr "net start AudioSrv" /st 13:25 /ru SYSTEM
    schtasks /create /sc daily /tn "静音2" /tr "net stop AudioSrv" /st 18:00 /ru SYSTEM
    schtasks /create /sc daily /tn "取消静音3" /tr "net start AudioSrv" /st 19:00 /ru SYSTEM
    schtasks /create /sc daily /tn "静音3" /tr "net stop AudioSrv" /st 19:31 /ru SYSTEM
    color E0
    set /p choice=是否删除所有静音任务(Y/N)?
    if /I !choice! == Y (
        schtasks /delete /tn "取消静音1" /f
        schtasks /delete /tn "静音1" /f
        schtasks /delete /tn "取消静音2" /f
        schtasks /delete /tn "静音2" /f
        schtasks /delete /tn "取消静音3" /f
        schtasks /delete /tn "静音3" /f
    )
    color 2F
    echo 提示:完成!
    pause
    cls
    goto MENU
) else if !choice! == 3 (
    title 修改密码
    echo 请输入新密码:
    set /p password=
    cls
    echo 密码正在存储......
    echo !password!>"!password_file!"
    echo 密码正在加密......
    powershell -command "$sha512 = [System.Security.Cryptography.SHA512]::Create(); $saltBytes = [System.Text.Encoding]::UTF8.GetBytes('%salt%'); $sourceBytes = [System.IO.File]::ReadAllBytes('!password_file!'); $saltedBytes = $sourceBytes + $saltBytes; $hashBytes = $sha512.ComputeHash($saltedBytes); $hashString = [System.BitConverter]::ToString($hashBytes).Replace('-', '').ToLower(); [System.IO.File]::WriteAllText('!hash_password_file!', $hashString)"
    echo 加密完成,正在清理缓存......
    del "!password_file!"
    echo 密码修改成功。
    pause
    cls
    goto MENU
) else if !choice! == 4 (
    title 作者信息
    echo 作者:高远
    echo 手机:138 1055 5080
    echo 邮箱:GaoYuan13810088206@163.com
    echo 20236月 毕业于昌平二中北校区
    echo ——————————————————本信息截止于2023626日——————————————————
    pause
    cls
    goto MENU
) else if !choice! == 0 (
    title 即将退出程序
    echo 感谢使用本程序。
    pause
    exit
) else (
    echo 无效选项,请重新输入。
    pause
    cls
    goto MENU
)

加入自动静音之后就不行了。

【相关推荐】




如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^