Advertisement
PoetralesanA

FIX IE 2

Jul 15th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. 'A class for changing the WebBrowser control's document emulation.
  2. 'Written by Visual Vincent, 2017.
  3.  
  4. Imports Microsoft.Win32
  5. Imports System.Security
  6. Imports System.Windows.Forms
  7. ' InternetExplorer.SetLatestBrowserEmulation(InternetExplorer.RegistryRoot.HKEY_LOCAL_MACHINE)
  8. 'HKEY_CURRENT_USER is recommended if you do not want to run your application with administrative privileges.
  9. 'InternetExplorer.SetLatestBrowserEmulation(InternetExplorer.RegistryRoot.HKEY_CURRENT_USER)
  10. Public NotInheritable Class InternetExplorer
  11. Private Sub New()
  12. End Sub
  13.  
  14. Public Const InternetExplorerRootKey As String = "Software\Microsoft\Internet Explorer"
  15. Public Const BrowserEmulationKey As String = InternetExplorerRootKey & "\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
  16. Public Const ActiveXObjectCachingKey As String = InternetExplorerRootKey & "\MAIN\FeatureControl\FEATURE_OBJECT_CACHING"
  17.  
  18. Private Shared ReadOnly WebBrowserInstance As New WebBrowser 'Used to get the current IE version in a .NET-friendly manner.
  19.  
  20. Public Enum BrowserEmulation As Integer
  21. IE7 = 7000
  22. IE8 = 8000
  23. IE8Standards = 8888
  24. IE9 = 9000
  25. IE9Standards = 9999
  26. IE10 = 10000
  27. IE10Standards = 10001
  28. IE11 = 11000
  29. IE11Edge = 11001
  30. End Enum
  31.  
  32. Public Shared Sub SetLatestBrowserEmulation(ByVal Root As RegistryRoot)
  33. Dim Emulation As BrowserEmulation = BrowserEmulation.IE7
  34. Select Case WebBrowserInstance.Version.Major
  35. Case Is >= 11 : Emulation = BrowserEmulation.IE11Edge
  36. Case 10 : Emulation = BrowserEmulation.IE10Standards
  37. Case 9 : Emulation = BrowserEmulation.IE9Standards
  38. Case 8 : Emulation = BrowserEmulation.IE8Standards
  39. End Select
  40. InternetExplorer.SetBrowserEmulation(Root, Emulation)
  41. End Sub
  42.  
  43. Public Shared Sub SetBrowserEmulation(ByVal Root As RegistryRoot, ByVal Emulation As BrowserEmulation)
  44. Using RootKey As RegistryKey = Root.Root
  45. Dim EmulationKey As RegistryKey = RootKey.OpenSubKey(BrowserEmulationKey, True)
  46. If EmulationKey Is Nothing Then EmulationKey = RootKey.CreateSubKey(BrowserEmulationKey, RegistryKeyPermissionCheck.ReadWriteSubTree)
  47.  
  48. Using EmulationKey
  49. EmulationKey.SetValue(Process.GetCurrentProcess().ProcessName & ".exe", CType(Emulation, Integer), RegistryValueKind.DWord)
  50. End Using
  51. End Using
  52. End Sub
  53.  
  54. Public Shared Sub SetActiveXObjectCaching(ByVal Root As RegistryRoot, ByVal Enabled As Boolean)
  55. Using RootKey As RegistryKey = Root.Root
  56. Dim ObjectCachingKey As RegistryKey = RootKey.OpenSubKey(ActiveXObjectCachingKey, True)
  57. If ObjectCachingKey Is Nothing Then ObjectCachingKey = RootKey.CreateSubKey(ActiveXObjectCachingKey, RegistryKeyPermissionCheck.ReadWriteSubTree)
  58.  
  59. Using ObjectCachingKey
  60. ObjectCachingKey.SetValue(Process.GetCurrentProcess().ProcessName & ".exe", CType(If(Enabled, 1, 0), Integer), RegistryValueKind.DWord)
  61. End Using
  62. End Using
  63. End Sub
  64.  
  65. Public NotInheritable Class RegistryRoot
  66. Private _root As RegistryKey
  67.  
  68. Public ReadOnly Property Root As RegistryKey
  69. Get
  70. Return _root
  71. End Get
  72. End Property
  73.  
  74. Public Shared ReadOnly Property HKEY_LOCAL_MACHINE As RegistryRoot
  75. Get
  76. Return New RegistryRoot(Registry.LocalMachine)
  77. End Get
  78. End Property
  79.  
  80. Public Shared ReadOnly Property HKEY_CURRENT_USER As RegistryRoot
  81. Get
  82. Return New RegistryRoot(Registry.CurrentUser)
  83. End Get
  84. End Property
  85.  
  86. Private Sub New(ByVal Root As RegistryKey)
  87. Me._root = Root
  88. End Sub
  89. End Class
  90. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement