How to play non-default system sounds in .NET

I want to use .NET code in my application to play system sounds-if I want to use Beep, Asterisk, etc. I have no problem, because I can use:

My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)

But what if I want to play something like “menu popup”? By default, this sound is turned off in the Windows default sound scheme, but if the user sets this sound to perform certain operations, I want to play it.

The user can assign any wav file for this operation, So I want to find the sound they assigned (if any) and play it. Compatibility with the Windows version is also important.

Of course, playing it is not a problem, because I can use:< /p>

My.Computer.Audio.Play(strWAVFile)

So the question is how to find it.

The wave sound files of system events are stored in the system registry. They have existed since Windows 95, so compatibility is not a problem.

Check this registry key to find the sound played for the event:

HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default

code>

For "menu popup", as you said, you can read the default value from this registry key:

HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\MenuPopup\.Current

So you would write code like this:

Dim rk = Registry.CurrentUser.OpenSubKey("AppEvents\Schemes\Apps\.Default\" & _
"MenuPopup\.Current")
Dim soundFile = rk.GetValue("")

If soundFile <> "" Then
My.Computer.Audio.Play(soundFile)
End If

I'm playing it I checked whether the soundFile variable is empty before, because not every event has a sound associated with it, and you don't want the application to stop working because of a sound file that cannot be found.

I want to use .NET code in my application to play system sounds-if I want to use Beep, Asterisk, etc. I have no problem, because I can use:

My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)

But what if I want to play something like "menu popup"? By default, this sound is turned off in the Windows default sound scheme, but if the user sets this sound to perform certain operations, I want to play it.

The user can assign any wav file for this operation, So I want to find the sound they assigned (if any) and play it. Compatibility with the Windows version is also important.

Of course, playing it is not a problem, because I can use:< /p>

My.Computer.Audio.Play(strWAVFile)

So the question is about how to find it.

< /p>

The wave sound files of system events are stored in the system registry. They have been there since Windows 95, so compatibility is not a problem.

Check this registry key to find Sound played for the event:

HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default

For "menu popup", as you said, you can read the default value from this registry key:

HKEY_CURRENT_USER\AppEvents \Schemes\Apps\.Default\MenuPopup\.Current

So you would write code like this:

Dim rk = Registry.CurrentUser.OpenSubKey("AppEvents\Schemes\Apps\.Default\" & _
"MenuPopup\.Current")
Dim soundFile = rk.GetValue("")

If soundFile <> "" Then
My.Computer.Audio.Play(soundFile)
End If

I checked whether the soundFile variable is empty before playing, Because not every event has a sound associated with it, and you don't want the application to stop working because of a sound file that cannot be found.

< /p>

Leave a Comment

Your email address will not be published.