1

I have set up a scheduled task to restore the shutdown sound Windows 10 (Pro) is missing by default. I set up that event 1074 triggers powershell.exe playing the sound with this argument:

-c (New-Object Media.SoundPlayer 'F:\Folder\shutdown.wav').PlaySync();

The sound starts to play but gets cut in 1-2 seconds, although there's time to finish it before the computer actually shuts down. I started to look for a way to set a minimal duration the task would run without interruption or the computer shutting it down. I was happy to find this thread: Play a sound (maybe WAV?) from Windows line command, and thought I could utilize a modified argument:

-c (New-Object Media.SoundPlayer 'F:\Folder\shutdown.wav').Play(); Start-Sleep -s 10; Exit;

This would play the first 10 second of the sound which is actually 8 seconds long, but still interrupts the same way after 1-2 seconds.

Are there any other arguments I could utilize to achieve that the sound gets played before the computer shuts down?

Thank you

AndrewT
  • 21

1 Answers1

1

Turns out Windows10 has a built in but (at least for me) quite hidden option to force an already initiated shutdown to let finish specified powershell scripts.

So I ended up removing the scheduled task, but kept the original command with the arguments, and saved the line into a powershell script file, like C:\PlayShutdownSound.ps1: powershell.exe -c (New-Object Media.SoundPlayer 'C:\Folder\shutdown.wav').PlaySync();

Then went into the Group Policies section (gpedit.msc)

  • computer configuration
  • windows settings
  • scripts (startup/shutdown)
  • shut down
  • properties
  • powershell scripts
  • add powershell script (browsed here for C:\PlayShutdownSound.ps1)
  • run windows powershell script first
AndrewT
  • 21