1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

パソコンを特定の時間に自動でシャットダウンする

Last updated at Posted at 2024-03-09

○やりたいこと

夜の9時45分になったらPCをシャットダウンさせる。夜更かし防止!!
10分前の9時35分に画面になにかしら通知的なやつを出したい

○実現方法

PCシャットダウンするバッチファイルを作って9:44にタスクスケジューラーで実行
9:44に1分後に電源が切れる通知が表示される

○結果

適当な時間にタスクスケジューラを実行させて成功
10分前の9:35に通知ではなく1分前になったけど良しとする
9:44で試していないけど良しとする!

○NW環境

Win11pro

○設定

batファイルの中身

shutdown /s
文字コード utf-8

ハマったところ

なし

わからなかったところ

SJISじゃないと動かない思ってたが動いた。Win11だからか?

タスクスケジューラの設定

ハマったところ

バッテリー駆動だったので時間になってもタスクが実行されなかった。
条件指定方法が電源接続時じゃないと実行されなかった。
ネットワークの接続を条件に変更したらタスクが実行された。
スクリーンショット 2024-03-09 213241.png

わからなかったところ

タスクスケジューラでバッチファイル実行時とバッチファイルダブルクリックではシャットダウンされるまでの動作が少し異なる。
タスクスケジューラでは、1分後にシャットダウンされる旨のダイアログが表示されてから1分後くらいにPCがシャットダウンされる。
スクリーンショット 2024-03-07 215827.png

以下が記載されたバッチファイルを実行すると即時シャットダウンされる。
"shutdown /i"

○その他

コマンドプロンプトで"shutdown ?"とかでヘルプ表示される
文字コードutf-8だったけど実行できた

○参考記事

・shutdownコマンドについて
https://learn.microsoft.com/ja-jp/windows-server/administration/windows-commands/shutdown

・Windowsコマンドについて
https://learn.microsoft.com/ja-jp/windows-server/administration/windows-commands/windows-commands

・バッチファイルについて
https://qiita.com/talesleaves/items/8990a55b7a770de3d34f
https://www.tohoho-web.com/ex/bat.html
https://qiita.com/sksmnagisa/items/8c4c1788af44cc1dc63a

・タスクスケジューラーについて
https://learn.microsoft.com/ja-jp/windows/win32/taskschd/about-the-task-scheduler
https://qiita.com/Richard_Roe/items/44e16841f16ee40c6113

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?