LoginSignup
10
12

More than 1 year has passed since last update.

◇Windowsのバッチファイルでトーストを使って通知する

Last updated at Posted at 2022-07-29

◇トーストを使って通知する

Toast.gif

トーストを利用するとバッチを終了し閉じたあとでも通知に記録を残すことができます。
PowerShellで実現できます。

トーストによる通知を行うサンプル

@echo off


set ToastMsg=\"バッチファイルからトースト通知します。`n行数も増やせます`n1`n2`n3`n4\"
PowerShell.exe ^&{$m=%ToastMsg%;$a='%comspec%';$t=[Windows.UI.Notifications.ToastNotificationManager,Windows.UI.Notifications,ContentType=WindowsRuntime]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType,Windows.UI.Notifications,ContentType=WindowsRuntime]::ToastText01);$t.GetElementsByTagName('text').Item(0).InnerText=$m;[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($a).Show($t);}


echo Message Strings.
echo.
echo %ToastMsg%
echo.


:: 終了処理(エクスプローラーから起動されていた場合はPauseする);
:EndProcess
echo %cmdcmdline%|find /i "%~f0">NUL
if %ERRORLEVEL% equ 0 (pause)
goto :eof

Powershellをバッチに埋め込もうとしないで使う場合はもっと色々なことができるのですが、バッチ一行でシンプルにするためメッセージのみです。
※サンプルではメッセージ文を編集しやすくするため、2行に分けています。

メッセージ文 は、「\”」 で括ります。「`n」で改行ができます。

おわりに

他にも「⧉Windowsのバッチファイルのテクニックをご紹介します」にてご紹介させて頂いております。
お時間ありましたら覗いてみてください
お粗末様でした。

10
12
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
10
12