VB.NET - Upgrading to the newest IE when using the Webbrowser Control-VBForums
Results 1 to 6 of 6

Thread: VB.NET - Upgrading to the newest IE when using the Webbrowser Control

  1. #1

    Thread Starter
    Fanatic Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,009

    Talking VB.NET - Upgrading to the newest IE when using the Webbrowser Control

    Howdy!

    I am hoping this will be very useful, as it was a question that lead me on a wild goose chase to track down code in c# - but I converted it and tested it and it works very effectively.


    The Issue

    The Webbrowser control is outdated - and was never re-released for updates.

    Solution What it does
    Programically "Upgrade" the webbrowser control.

    It will upgrade to the most qualified version the computer has installed

    And it Does Include Microsoft Edge already See the codes via the link in the c# orgin and source section below
    Getting Started
    You need :

    A Windows Form Project with :

    - A Form
    - A webbrowser control

    - A Class File

    Now the code:

    Inside the class file
    The following code uses the name WebBrowserHelper - It is assumed you rename the class

    Code:
    Public Class WebBrowserHelper
        Public Shared Function GetEmbVersion() As Integer
            Dim ieVer As Integer = GetBrowserVersion()
    
            If ieVer > 9 Then
                Return ieVer * 1000 + 1
            End If
    
            If ieVer > 7 Then
                Return ieVer * 1111
            End If
    
            Return 7000
        End Function
        ' End Function GetEmbVersion
        Public Shared Sub FixBrowserVersion()
            Dim appName As String = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location)
            FixBrowserVersion(appName)
        End Sub
    
        Public Shared Sub FixBrowserVersion(appName As String)
            FixBrowserVersion(appName, GetEmbVersion())
        End Sub
        ' End Sub FixBrowserVersion
        ' FixBrowserVersion("<YourAppName>", 9000);
        Public Shared Sub FixBrowserVersion(appName As String, ieVer As Integer)
            FixBrowserVersion_Internal("HKEY_LOCAL_MACHINE", appName & Convert.ToString(".exe"), ieVer)
            FixBrowserVersion_Internal("HKEY_CURRENT_USER", appName & Convert.ToString(".exe"), ieVer)
            FixBrowserVersion_Internal("HKEY_LOCAL_MACHINE", appName & Convert.ToString(".vshost.exe"), ieVer)
            FixBrowserVersion_Internal("HKEY_CURRENT_USER", appName & Convert.ToString(".vshost.exe"), ieVer)
        End Sub
        ' End Sub FixBrowserVersion 
        Private Shared Sub FixBrowserVersion_Internal(root As String, appName As String, ieVer As Integer)
            Try
                'For 64 bit Machine 
                If Environment.Is64BitOperatingSystem Then
                    Microsoft.Win32.Registry.SetValue(root & Convert.ToString("\Software\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"), appName, ieVer)
                Else
                    'For 32 bit Machine 
                    Microsoft.Win32.Registry.SetValue(root & Convert.ToString("\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"), appName, ieVer)
    
    
                End If
                ' some config will hit access rights exceptions
                ' this is why we try with both LOCAL_MACHINE and CURRENT_USER
            Catch generatedExceptionName As Exception
            End Try
        End Sub
        ' End Sub FixBrowserVersion_Internal 
        Public Shared Function GetBrowserVersion() As Integer
            ' string strKeyPath = @"HKLM\SOFTWARE\Microsoft\Internet Explorer";
            Dim strKeyPath As String = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer"
            Dim ls As String() = New String() {"svcVersion", "svcUpdateVersion", "Version", "W2kVersion"}
    
            Dim maxVer As Integer = 0
            For i As Integer = 0 To ls.Length - 1
                Dim objVal As Object = Microsoft.Win32.Registry.GetValue(strKeyPath, ls(i), "0")
                Dim strVal As String = System.Convert.ToString(objVal)
                If strVal IsNot Nothing Then
                    Dim iPos As Integer = strVal.IndexOf("."c)
                    If iPos > 0 Then
                        strVal = strVal.Substring(0, iPos)
                    End If
    
                    Dim res As Integer = 0
                    If Integer.TryParse(strVal, res) Then
                        maxVer = Math.Max(maxVer, res)
                    End If
                    ' End if (strVal != null)
                End If
            Next
            ' Next i
            Return maxVer
        End Function
        ' End Function GetBrowserVersion 
    End Class
    In Form1 Call the class to do its job using the following:
    It is reccomended to do this at load time to prevent any errors or mishaps occuring.

    Code:
     WebBrowserHelper.FixBrowserVersion()
    And thats it!

    C# Origin - And source

    The orgin of the code comes from StackOverFlow Answer in the Update 1 Section.
    See that here


    Thanks! If you got any ideas - code clean up or otherwise Feel Free to add!!



    Known issues:


    Background: There are a few known issues, it has nothing really to do with the class, rather Microsofts abandonment of the Webbrowser control/IE for Edge, without upgrading, the webbrowser control, to the same version - or adding compatibility to Edge (Like a properties menu to choose which versions to use)

    - Failure to Render some HTML pages, e.g. Blank Screens

    - Failure to supress compatibility dialogs.

    - Slow Rendering

    - Some sites won't work
    Last edited by jdc20181; Nov 8th, 2017 at 06:14 PM.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  2. #2
    New Member
    Join Date
    Jun 2017
    Posts
    1

    Re: VB.NET - Upgrading to the newest IE when using the Webbrowser Control

    How tO Convert c# to Vb net like That?

  3. #3

    Thread Starter
    Fanatic Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,009

    Re: VB.NET - Upgrading to the newest IE when using the Webbrowser Control

    It is already converted to vb.net. I posted where I got the source from.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  4. #4
    Fanatic Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    746

    Re: VB.NET - Upgrading to the newest IE when using the Webbrowser Control

    Unfortunately, this doesn't help with the unsupported browser warning from Google Maps Javascript API even though they direct you to the same info. In fact, this seems to have no effect at all in my case. If I remove the X-UA-Compatible meta tag from my HTML file, it shows a blank screen as it did before I added that tag.

    If I can't find a way to auto-dismiss that warning (the map works fine if you click Dismiss), I may try to use Chromium/cefsharp for the browser.


    EDIT: Well, I take it back somewhat. Perhaps because IE is 32-bit or the .Net app is 32-bit, but the new value needs to be put into the registry location the code says is for 32-bit OS and not the 64-bit like it did.

    I added it to HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION and no warning shows up!

    EDIT 2: A comment on the original source suggested he look for 64-bit PROCESS vs OS and that led me to this VB.Net Class
    Last edited by topshot; Nov 8th, 2017 at 05:05 PM. Reason: Found a workaround

  5. #5

    Thread Starter
    Fanatic Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,009

    Re: VB.NET - Upgrading to the newest IE when using the Webbrowser Control

    Quote Originally Posted by topshot View Post
    Unfortunately, this doesn't help with the unsupported browser warning from Google Maps Javascript API even though they direct you to the same info. In fact, this seems to have no effect at all in my case. If I remove the X-UA-Compatible meta tag from my HTML file, it shows a blank screen as it did before I added that tag.

    If I can't find a way to auto-dismiss that warning (the map works fine if you click Dismiss), I may try to use Chromium/cefsharp for the browser.


    EDIT: Well, I take it back somewhat. Perhaps because IE is 32-bit or the .Net app is 32-bit, but the new value needs to be put into the registry location the code says is for 32-bit OS and not the 64-bit like it did.

    I added it to HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION and no warning shows up!

    EDIT 2: A comment on the original source suggested he look for 64-bit PROCESS vs OS and that led me to this VB.Net Class
    I actually reccomend using GeckoFX, its via Nuget its easy to set up, you will however need to edit the XML because it is older (from when tehy changed the path in VS it isnt that old really only a year)

    Solution for the errors, was provided in this thread: http://www.vbforums.com/showthread.p...hlight=Strange

    You should edit this file before building, after editing, add the DLLS to the project - from the package folder.

    Gecko is better and doesn't give you any kind of warnings - and it renders faster.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  6. #6
    Fanatic Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    746

    Re: VB.NET - Upgrading to the newest IE when using the Webbrowser Control

    FWIW I simplified down to this class
    Code:
    Imports Microsoft.Win32
    ''' <summary>
    ''' Creates registry entry to allow standard WebBrowser control to operate at maximum compatibility instead of IE7
    ''' NOTE: the entry is specific to an application so must be done for any program that uses WebBrowser
    ''' </summary>
    ''' <remarks></remarks>
    Public Class WebBrowserUpdater
    
        Public Shared Sub FixBrowserVersion()
            Try
                Dim BrowserVer As Integer, RegVal As Integer
    
                ' get the installed IE version
                Using Wb As New WebBrowser()
                    BrowserVer = Wb.Version.Major
                End Using
    
                ' set the appropriate IE version
                If BrowserVer >= 11 Then
                    RegVal = 11001
                ElseIf BrowserVer = 10 Then
                    RegVal = 10001
                ElseIf BrowserVer = 9 Then
                    RegVal = 9999
                ElseIf BrowserVer = 8 Then
                    RegVal = 8888
                Else
                    RegVal = 7000
                End If
    
                ' set the actual key
                Using Key As RegistryKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree)
                    If Key.GetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe") Is Nothing Then
                        Key.SetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe", RegVal, RegistryValueKind.DWord)
                    End If
                End Using
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
        End Sub
    
    End Class
    Technically, setting the key value to 0 or some unknown value would also work but isn't officially supported, of course.

    cefSharp works well except that the application I was trying to update made extensive use of embedded Javascript in our local HTML page (for Google Maps), which looked like it would be more pain than it was worth right now to get it working and tested properly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.