Option Explicit On
Option Strict On

Imports System.Runtime.InteropServices
Imports System.IO
Imports Microsoft.Win32

Public Class Form1

    Private WebBrowser As New ExWebBrowser

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ExWebBrowser.CreateRenderingModeRegkey(ExWebBrowser.Emulation.IE11Edge)
        Me.Controls.Add(Me.WebBrowser)
        Me.WebBrowser.Dock = DockStyle.Fill
        Me.WebBrowser.DisableNavigationSound = True
        Me.WebBrowser.GoHome()
    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        ExWebBrowser.DeleteRenderingModeRegkey()
    End Sub

End Class

Public Class ExWebBrowser
    Inherits WebBrowser

    Public Enum INTERNETFEATURELIST
        FEATURE_OBJECT_CACHING = 0
        FEATURE_ZONE_ELEVATION = 1
        FEATURE_MIME_HANDLING = 2
        FEATURE_MIME_SNIFFING = 3
        FEATURE_WINDOW_RESTRICTIONS = 4
        FEATURE_WEBOC_POPUPMANAGEMENT = 5
        FEATURE_BEHAVIORS = 6
        FEATURE_DISABLE_MK_PROTOCOL = 7
        FEATURE_LOCALMACHINE_LOCKDOWN = 8
        FEATURE_SECURITYBAND = 9
        FEATURE_RESTRICT_ACTIVEXINSTALL = 10
        FEATURE_VALIDATE_NAVIGATE_URL = 11
        FEATURE_RESTRICT_FILEDOWNLOAD = 12
        FEATURE_ADDON_MANAGEMENT = 13
        FEATURE_PROTOCOL_LOCKDOWN = 14
        FEATURE_HTTP_USERNAME_PASSWORD_DISABLE = 15
        FEATURE_SAFE_BINDTOOBJECT = 16
        FEATURE_UNC_SAVEDFILECHECK = 17
        FEATURE_GET_URL_DOM_FILEPATH_UNENCODED = 18
        FEATURE_TABBED_BROWSING = 19
        FEATURE_SSLUX = 20
        FEATURE_DISABLE_NAVIGATION_SOUNDS = 21
        FEATURE_DISABLE_LEGACY_COMPRESSION = 22
        FEATURE_FORCE_ADDR_AND_STATUS = 23
        FEATURE_XMLHTTP = 24
        FEATURE_DISABLE_TELNET_PROTOCOL = 25
        FEATURE_FEEDS = 26
        FEATURE_BLOCK_INPUT_PROMPTS = 27
        FEATURE_ENTRY_COUNT = 28
    End Enum

    Public Enum INTERNETFEATUREFLAGS
        SET_FEATURE_ON_THREAD = &H1
        SET_FEATURE_ON_PROCESS = &H2
        SET_FEATURE_IN_REGISTRY = &H4
        SET_FEATURE_ON_THREAD_LOCALMACHINE = &H8
        SET_FEATURE_ON_THREAD_INTRANET = &H10
        SET_FEATURE_ON_THREAD_TRUSTED = &H20
        SET_FEATURE_ON_THREAD_INTERNET = &H40
        SET_FEATURE_ON_THREAD_RESTRICTED = &H80
    End Enum

    Public Enum Emulation
        IE11Edge = 11001
        IE11 = 11000
        IE10Std = 10001
        IE10 = 10000
        IE9Std = 9999
        IE9 = 9000
        IE8Std = 8888
        IE8 = 8000
        IE7 = 7000
    End Enum

    Private Const FEATURE_BROWSER_EMULATION As String = "Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"

    <DllImport("urlmon.dll")>
    Private Shared Function CoInternetSetFeatureEnabled(
        ByVal FeatureEntry As INTERNETFEATURELIST,
        ByVal dwFlags As INTERNETFEATUREFLAGS,
        ByVal fEnable As Boolean) _
        As Integer
    End Function

    Private _DisableNavigationSound As Boolean

    Property DisableNavigationSound As Boolean
        Get
            Return Me._DisableNavigationSound
        End Get
        Set(value As Boolean)
            Me._DisableNavigationSound = value
            CoInternetSetFeatureEnabled(INTERNETFEATURELIST.FEATURE_DISABLE_NAVIGATION_SOUNDS, INTERNETFEATUREFLAGS.SET_FEATURE_ON_PROCESS, value)
        End Set
    End Property

    Public Shared Sub CreateRenderingModeRegkey(EmulationMode As Emulation)
        Using Regkey As RegistryKey = Registry.CurrentUser.CreateSubKey(FEATURE_BROWSER_EMULATION)
            Regkey.SetValue(GetReleaseBuildName, EmulationMode, RegistryValueKind.DWord)
            Regkey.SetValue(GetDebugBuildName, EmulationMode, RegistryValueKind.DWord)
        End Using
    End Sub

    Public Shared Sub DeleteRenderingModeRegkey()
        Using Regkey As RegistryKey = Registry.CurrentUser.CreateSubKey(FEATURE_BROWSER_EMULATION)
            Regkey.DeleteValue(GetReleaseBuildName)
            Regkey.DeleteValue(GetDebugBuildName)
        End Using
    End Sub

    Private Shared Function GetReleaseBuildName() As String
        Return Path.GetFileName(Application.ExecutablePath)
    End Function

    Private Shared Function GetDebugBuildName() As String
        Return GetReleaseBuildName.Replace(".exe", ".svhost.exe")
    End Function

End Class