Powershell -- how to play different system sounds?

When I do this:

I get an obnoxious beep.

When I do any of the below, I expect different sounds, but they are all the same. How do I access the native sounds ?

[System.Media.SystemSounds]::Asterisk.Play()
[System.Media.SystemSounds]::Beep.Play()
[System.Media.SystemSounds]::Exclamation.Play()
[System.Media.SystemSounds]::Hand.Play()
[System.Media.SystemSounds]::Question.Play()

(note, I do not want to play a file... I am looking to play sounds native to windows)

3

1 Answer

This is not a Powershell code issue or feature. It is a Windows OS setting.

Your issue is because they are the default sounds, which are simply a pointer to a .wav file.

If you want those to be different, you have to choose a different .wav file from the Windows folder where they are located.

C:\Windows\Media

So, as for your comment ***note, I do not want to play a file.***, yes, yes you do; but just one that is already on your system default location noted above.

Just go to Control Panel and select Sounds, or right-click the speaker in your taskbar and select sounds. Either way, change as needed manually.

Your options then become this ...

[System.Console]::Beep()
[System.Console]::Beep(1000,300)

or this...

(New-Object System.Media.SoundPlayer $(Get-Random $(Get-ChildItem -Path "$env:windir\Media\*.wav").FullName)).Play()
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like