編集27-05-2918(関連する質問):この方法でスケジュールされたシャットダウンが「タスクスケジューラ」(Windows 10)に表示されないのはなぜですか?
いくつかのコードを含む.BATがあります。次のコードを追加します。
- 現在シャットダウンがアクティブになっていることをユーザーに伝えます(BATが シャットダウン前に複数回実行された場合)およびそのシャットダウンがスケジュールされたとき。
- 現在、シャットダウンを再スケジュールしようとすると、BATはエラーレベル1990を表示します。そのメッセージを表示しないようにする方法が必要です。
また、次のことも試してみたいと思います(どうすればいいかわかりません)。
- X = Listの場合、特定の日付にスケジュールされた複数の将来のシャットダウン(日付と時刻)を表示し、繰り返し発生するスケジュールされたシャットダウンも表示します。
- 個々の将来のシャットダウンを追加または削除したり、編集したりできるようにします。
以下のコードはかなりうまく機能しますが、ポイント.1 .2および.3を達成することなく
編集: コードを更新し、ポイント.2を解決できました:2>を使用します NUL
@echo off
setlocal enabledelayedexpansion
goto :MAIN
:INVALID
Echo X = "%input01%" is invalid.
timeout 5
goto :MAIN
:NOW
C:\Windows\System32\shutdown /s
Echo Shutting down now.
pause
goto :MAIN
:STOP
Echo Attempting to stop any Scheduled Shutdowns.
Echo/
C:\Windows\System32\shutdown /a 2>NUL
if NOT ERRORLEVEL 1116 (Echo Scheduled shutdown stopped.) ELSE (
Echo Unable to abort the system because no shutdown was in progress (1116^)
)
Timeout 10
goto :MAIN
:MAIN
cls
set "input01="
set "ExVal01="
Echo JimmyWilliams - 20180523
Echo/
Echo This will cause the computer to automatically shutdown in X minutes,
Echo and will override any existing scheduled shutdown.
Echo/
Echo Enter "X = Stop", cancel any currently active future shutdown.
Echo Enter "X = Quit", to close this program.
Echo/
Set /p "input01=1. Enter a whole positive number: X = "
if "%input01%"=="" goto :INVALID
Set /a ExVal01="%input01%"*60
if /I "%input01%"=="Quit" goto :Quit
if /I "%input01%"=="Stop" goto :STOP
if %input01%==0 goto :NOW
if %ExVal01%==0 goto :INVALID
if %input01% LSS 0 goto :INVALID
C:\Windows\System32\shutdown /s /t %ExVal01% 2>NUL
if ERRORLEVEL 1190 (echo Rescheduled to shutdown in %input01% mins.
C:\Windows\System32\shutdown /a
C:\Windows\System32\shutdown /s /t %ExVal01%
) ELSE (echo Shutting down in %input01% mins.
)
Timeout 10
goto :MAIN
:QUIT
Echo Quiting the Program.
pause
:EOF:
回答 1 件
これが私の作業コードです。 冗長性を削除したり、コードを高速化したり、よりクリーンにするためのトリックを知っている人がいれば、それは素晴らしいことです!私は初心者ですので、提案やコメントをお寄せください。
ありがとう!
ジェームス
スケジュールされたシャットダウンのカレンダーとタイマーなしの別の簡単なバージョンがあります (EXEなしで動作します)。