I have network monitoring server VM and always on win10 PC which displays monitoring dashboard. I want to implement sound alert on win10 PC when monitoring server generates alert.
Monitoring server runs CentOS7 and has functionality to execute bash script on alert event. I installed and configured IIS and php7.3 on win10 PC. My idea is to use
curl http://x.x.x.x/index.php
from server when alert is generated. index.php executes powershell script on win10 PC which plays alert sound.
index.php
Shell_Exec ('powershell.exe C:\inetpub\wwwroot\sound.ps1');
echo Shell_Exec ('powershell.exe "Get-Process"); //This is for testing
sound.ps1
$sound = new-Object System.Media.SoundPlayer;
$sound.SoundLocation="C:\inetpub\wwwroot\alert.wav";
$sound.Play();
When powershell script executed localy sound is played. When win10 PC accessed with curl I get information about running processes on computer, but no sound is played. As I understand powershell script is executed not as logged in user so windows doesn't play the sound. How can I make this work? Or is there better solution for this?
EDIT:
I added start-transcript
line to sound.ps1
:
start-transcript -Path C:\ProgramData\log.txt
$sound = new-Object System.Media.SoundPlayer;
$sound.SoundLocation="C:\inetpub\wwwroot\alert.wav";
$sound.Play();
stop-transcript
Strangely I got like 0.5s playback of alert.wav when doing http request.
EDIT2: Added Start-sleep -s 5 to the end of sound.ps1 and it works as intended. (alert.wav playback duration is 3s)