Turning on and off Mail sound

Peter Karlström 216 Reputation points
2021-03-22T21:24:01.333+00:00

Hi

I want to turn mail sound on and off programmatically using Visual Basic or C#.

The settings used in previous versions of Windows was located in the registry’s CURRENT_USER AppEvents\Schemes\Apps.Default\MailBeep folder, but this settings seems to be ignored.

I have found bits of settings in HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\Outlook\Settings\Data\global_Mail_PlaySound, but changing the value in code has no effect in the client.

I don’t want to turn off sound totally, I just want to change the setting for mail sound to on or off using some code in VB or C# with an application argument.

This code does not do the trick:
Dim comArgs() As String = Environment.GetCommandLineArgs

For Each comArg In comArgs
    If comArg.ToLower.Contains("/on") Then
        'Sätt på ljudet
        Dim setValue As String = "{""name"":""Mail_PlaySound"",""itemClass"":""roamingsetting"",""id"":""RgAAAAA0zT-l4Q-tQLHwADYCw-ouBwDtV__ZDum8T7CsDsO5wuSsAAIBrEpfAADtV__ZDum8T7CsDsO5wuSsAAJfiXx-AAAA0"",""scope"":""Global"",""parentSetting"":"""",""secondaryKey"":"""",""status"":""SYNCEDTOSERVICE"",""type"":""Bool"",""timestamp"":0,""metadata"":"""",""value"":""true"",""isFirstSync"":""false""}"
        My.Computer.Registry.SetValue("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\Outlook\Settings\Data", "global_Mail_PlaySound", setValue)
        Exit For
    End If
    If comArg.ToLower.Contains("/off") Then
        'Stäng av ljudet                
        Dim setValue As String = "{""name"":""Mail_PlaySound"",""itemClass"":""roamingsetting"",""id"":""RgAAAAA0zT-l4Q-tQLHwADYCw-ouBwDtV__ZDum8T7CsDsO5wuSsAAIBrEpfAADtV__ZDum8T7CsDsO5wuSsAAJfiXx-AAAA0"",""scope"":""Global"",""parentSetting"":"""",""secondaryKey"":"""",""status"":""SYNCEDTOSERVICE"",""type"":""Bool"",""timestamp"":0,""metadata"":"""",""value"":""false"",""isFirstSync"":""false""}"
        My.Computer.Registry.SetValue("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\Outlook\Settings\Data", "global_Mail_PlaySound", setValue)
        Exit For
    End If
Next

Has anybody any idea on how to do this?

Regards
Peter Karlström

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,237 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,568 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,885 questions
{count} votes

Accepted answer
  1. Peter Karlström 216 Reputation points
    2021-03-23T07:46:53.317+00:00

    Hi

    You got me on the right track there. Thanks
    The actual value for mail sound is here:
    HKEY_CURRENT_USER\AppEvents\Schemes\Apps.Default\Notification.Mail.Current.
    Another misleading fact is that the filename is translated to Swedish, so I didn't find it with a search in the Registry.

    This is the new code:

    Sub main()

    Dim comArgs() As String = Environment.GetCommandLineArgs
    
    For Each comArg In comArgs
        If comArg.ToLower.Contains("/on") Then
            'Turn on sound
            Dim setValue As String = "C:\WINDOWS\media\notify.wav"
            My.Computer.Registry.SetValue("HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\Notification.Mail\.Current", "", setValue)
            Exit For
        End If
        If comArg.ToLower.Contains("/off") Then
            'Torn sound off
            Dim setValue As String = ""
            My.Computer.Registry.SetValue("HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\Notification.Mail\.Current", "", setValue)
            Exit For
        End If
    Next
    

    End Sub

    Thanks.

    0 comments No comments

0 additional answers

Sort by: Most helpful