我正在尝试创建一个应用程序来根据我开始观看电影之前设置的时间关闭我的电脑。
我在 .bat 文件中制作了它,位于此处:
@echo off
:BEGINING
echo ________________________
echo / 30 min /
echo / 45 min /
echo / 1 hour /
echo / 1 hour 30 mins (1.30) /
echo / 1 hour 45 min (1.45) /
echo / 2 hours /
echo / 2 hours 30 min (2.30) /
echo / 2 hours 45 min (2.45) /
echo ------------------------
set /p hourShutdown=Shutdown in:
if %hourShutdown%==0.30 (
::Shutting down in 30 minutes
set /p youSure=Shutting down in 30 minutes? Y/N:
goto CONFIRMATION30
)
if %hourShutdown%==0.45 (
set /p youSure=Shutting down in 45 minutes? Y/N:
goto CONFIRMATION45
)
if %hourShutdown%==1 (
::Shutting down in 1 hour
set /p youSure=Shutting down in %hourShutdown% hour? S/N:
goto CONFIRMATION1
)
if %hourShutdown%==1.30 (
::Shutting down in 1 hour and media
set /p youSure=Shutting down in 1 hour 30 minutes? Y/N:
goto CONFIRMATION130
)
if %hourShutdown%==1.45 (
::Shutting down in 1 hour and 45 minutes
set /p youSure=Shutting down in 1 hour and 45 minutes? Y/N:
goto CONFIRMATION145
)
if %hourShutdown%==2 (
::Shutting down in 2 hours
set /p youSure=Shutting down in %hourShutdown% hours? Y/N:
goto CONFIRMATION2
)
if %hourShutdown%==2.30 (
::Shutting down in 2 hours 30 minutes
set /p youSure=Shutting down in 2 hours and 30 minutes? Y/N:
goto CONFIRMATION230
)
if %hourShutdown%==2.45 (
::Shutting down in 2 hours 45 minutes
set /p youSure=Shutting down in 2 hours and 45 minutes? Y/N:
goto CONFIRMATION245
) else (
echo Time incorrectly introduced...
goto BEGINING
)
:CONFIRMATION30
if %youSure%==y (
shutdown -s -t 1800
) else (
goto BEGINING
)
:CONFIRMATION45
if %youSure%==y (
shutdown -s -t 2700
exit
) else (
goto BEGINING
)
:CONFIRMATION1
if %youSure%==y (
shutdown -s -t 3600
exit
) else (
goto BEGINING
)
:CONFIRMATION130
if %youSure%==y (
shutdown -s -t 4680
exit
) else (
goto BEGINING
)
:CONFIRMATION145
if %youSure%==y (
shutdown -s -t 5220
exit
) else (
goto BEGINING
)
:CONFIRMATION2
if %youSure%==y (
shutdown -s -t 7200
exit
) else (
goto BEGINING
)
:CONFIRMATION230
if %youSure%==y (
shutdown -s -t 8280
exit
) else (
goto BEGINING
)
:CONFIRMATION245
if %youSure%==y (
shutdown -s -t 8820
exit
) else (
goto BEGINING
)
pause
现在我制作了 .bat 文件,我想为其制作一个 GUI。我在互联网上进行了研究,发现了一种叫做 VBScript 的东西,我不需要安装所有 Visual Basic Studio 软件。
我几乎没有编码技能,.bat 代码是我目前能编码的最好的代码,所以有没有办法用 VBScript 将 .bat 文件变成 GUI .exe?
不。用允许您创建 GUI 的编程语言再次编写它(并编译为可执行文件,而 VBScript 则不然)。 是的,您必须为此学习一种不同的编程语言(至少是其中的一小部分)。
Visual Studio Community是免费的,可以快速下载,它也不再像以前那样大和重。
您可以在 Powershell 中运行。然而,这并不能让 GUI 部分的迁移变得更容易。您可能想看看这个。
不完全是您正在寻找的内容,但我创建了一个实用程序脚本。它缺乏精美的 GUI,但我相信它提供了出色的用户体验。我修改了你的脚本以适应其基本结构。您可以利用它来开发更有用的脚本,或者为另一个项目汲取灵感。
@echo off
chcp 65001
title System Maintenance Tool - 1.6.4
color 3f
:menu
cls
echo ======================================================================
echo System Maintenance Tool
echo ======================================================================
echo [1] System Settings
echo [0] Exit
echo ======================================================================
echo.
CHOICE /N /C 01 /M "Enter a number."
SET group=%ERRORLEVEL%
IF %group%==1 GOTO exit
IF %group%==2 GOTO sysconfig
:sysconfig
cls
echo ======================================================================
echo System Settings
echo ======================================================================
echo [1] Schedule a Computer Shutdown.
echo [0] Back.
echo ======================================================================
echo.
CHOICE /N /C 01 /M "Enter a number."
SET choice=%ERRORLEVEL%
IF %choice%==1 GOTO menu
IF %choice%==2 GOTO schedshutdown
:schedshutdown
set "countdown="
cls
echo ======================================================================
echo Schedule a Computer Shutdown
echo ======================================================================
echo [1] Cancel Scheduled Shutdown
echo [2] 30 min.
echo [3] 45 min.
echo [4] 1 hour.
echo [5] 1 hour 30 mins.
echo [6] 1 hour 45 min.
echo [7] 2 hours.
echo [8] 2 hours 30 min.
echo [9] 2 hours 45 min.
echo [0] Back.
echo ----------------------------------------------------------------------
CHOICE /N /C 0123456789 /M "Enter 0 to go back or select an option: "
SET choice=%ERRORLEVEL%
IF %choice%==1 GOTO sysconfig
IF %choice%==2 GOTO cancelsched
IF %choice%==3 GOTO 30min
IF %choice%==4 GOTO 45min
IF %choice%==5 GOTO 1hour
IF %choice%==6 GOTO 1hour30min
IF %choice%==7 GOTO 1hour45min
IF %choice%==8 GOTO 2hours
IF %choice%==9 GOTO 2hours30min
IF %choice%==10 GOTO 2hours45min
:cancelsched
cls
echo ======================================================================
echo Schedule a Computer Shutdown
echo ======================================================================
shutdown /a > nul
if %errorlevel% neq 0 (
echo No Scheduled Shutdown Found.
) else (
echo Scheduled Shutdown Cancelled.
)
echo.
echo ----------------------------------------------------------------------
echo Press any key to return.
pause > nul
GOTO schedshutdown
:30min
set "countdown=1800"
GOTO confirm
:45min
set "countdown=2700"
GOTO confirm
:1hour
set "countdown=3600"
GOTO confirm
:1hour30min
set "countdown=5400"
GOTO confirm
:1hour45min
set "countdown=6300"
GOTO confirm
:2hours
set "countdown=7200"
GOTO confirm
:2hours30min
set "countdown=9000"
GOTO confirm
:2hours45min
set "countdown=9900"
GOTO confirm
:confirm
set /a "hours=%countdown% / 3600"
set /a "remaining_seconds=%countdown% %% 3600"
set /a "minutes=%remaining_seconds% / 60"
cls
echo ======================================================================
echo Schedule a Computer Shutdown
echo ======================================================================
echo Do you want to confirm the computer shutdown in %hours% hour(s) and %minutes% minute(s)?
echo.
echo ----------------------------------------------------------------------
CHOICE /N /C 01 /M "Enter 0 to go back or 1 to Confirm: "
SET choice=%ERRORLEVEL%
IF %choice%==1 GOTO schedshutdown
IF %choice%==2 GOTO shutdown
:shutdown
shutdown /a
shutdown -s -t %countdown%
cls
echo ======================================================================
echo Schedule a Computer Shutdown
echo ======================================================================
echo The computer will shut down in %hours% hour(s) and %minutes% minute(s).
echo.
echo ----------------------------------------------------------------------
echo Press any key to return.
pause > nul
GOTO schedshutdown
:exit
exit