How to play system sounds in C#

.NET Framework allows playing system sounds using a simple code:

SystemSounds.[Type].Play(); 

But the SystemSounds class supports only 5 types of sound notifications: Asterisk, Beep, Exclamation, Hand, Question.

There is no easy way to play other standard sounds like LowBatteryAlarm, DeviceConnect, DeviceDisconnect, MailBeep, and others from the Windows Sound Scheme.

We in BgRnD are using following function in our C# projects:

public void PlaySystemSound(string RegistryName)
{
    string fileName = "";

    RegistryKey key = Registry.CurrentUser.OpenSubKey(String.Format(@"AppEvents\Schemes\Apps\.Default\{0}\.Current", RegistryName), false);
    try
    {
        fileName = (string)key.GetValue("", fileName);
    }
    finally
    {
        key.Close();
    }

    if (!File.Exists(fileName)) return;

    SoundPlayer player = new SoundPlayer(fileName);
    try
    {
        player.Play();
    }
    finally
    {
        player.Dispose();
    }
}

The function plays the sound resource specified by the RegistryName parameter. The set of possible names you can find in the System Registry at HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default path.

Windows Sounds in the System Registry
Screenshot of Registry Editor to understand where to take Registry Names of system sounds.

You can freely use (copy and paste) this function into any of your projects.

If you still have any programming questions about playing the Windows sound notifications, feel free to ask.

Backup of Firewall settings is Important

If you use a web server (no matter with Linux, Unix or Windows) you should keep it safe. The firewall is the first place where you need to setup the system security.

It is necessary to restrict access to the server by specific protocols and ports. More precisely, on the server firewalls you need to close all ports and open only the most necessary ones 🙂

Linux kernel firewall works with iptables space. You can manually make entries in the iptables configs (different files in /etc/ or /etc/sysconfig/ depending on the Linux version). If you use some visual management panel (Webmin, WHM, CPanel, Plesk, etc.) tuning the Linux firewall become a pleasure.

But independently of managing methods, do not forget to make a regular copies of the firewall settings! Accidental clicking of some button in control panel can suspend all the rules and make your server vulnerable. Deleting or modification of the configuration file by some hacking scripts can do the same.

In general, for servers on the Linux system, the regular backup of the iptables config files is a must do task for webmaster. Backups for security settings are usually scheduled on Unix and Windows servers too.

Backup firewall settings regularly and keep your web-servers secure!