How do I play default Windows sounds?

Sometimes, you might want to make your application a bit more audible. If you are using .NET 2.0, you can utilize the new System.Media namespace and its SystemSound and SystemSounds classes.

The SystemSounds class contains five static properties that you can use to retrieve instances of the SystemSound class. This class in turn contains the Play() method, which you can use to play the wave file associated with the sound in Windows Control Panel. Note that the user can also disable all sounds altogether, which would mean that no sound can be heard through the computer speakers.

To play for example the classical beep sound, you could use the following code:


Similarly, you could play the “Question” sound with this code:


The System.Media namespace is defined in System.dll, so there are no new DLLs you would need to add to your project’s references to use the above code.

[author: Jani Järvinen, C# MVP]