dcsimg
Results 1 to 11 of 11
  1. #1

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

    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

    - Shows as another browser engine (e.g. Mozilla) or wrong version than desired.

    Possible issues

    - Doesn't work with some older .NET framework versions



    Updates

    Updates to the class will be around soon, with fixes to known issues where possible - And fixing the code to work with newer frameworks with a possible issue.
    Last edited by jdc20181; May 9th, 2018 at 02:24 PM. Reason: Added for information etc.
    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
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,049

    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
    833

    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 04:05 PM. Reason: Found a workaround

  5. #5

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

    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
    833

    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.

  7. #7
    New Member
    Join Date
    Apr 2018
    Location
    Rome, Italy
    Posts
    3

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

    Thank you for the code, i have been looking for something like this for long.
    Yet i don't understand how i tell the system what version of IE to update to.
    I inserted the class in my project, and let's say I want to update my IE browser in by project to IE 10, so the value vould be 10001.
    My applications' exe is called Uranium.exe
    shall I put the command:

    FixBrowserVersion("Uranium.exe", 10001) in the _OnLoad event of my form?

    In this case, it did not work

  8. #8
    New Member
    Join Date
    Apr 2018
    Location
    Rome, Italy
    Posts
    3

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

    Quote Originally Posted by ademontis View Post
    Thank you for the code, i have been looking for something like this for long.
    Yet i don't understand how i tell the system what version of IE to update to.
    I inserted the class in my project, and let's say I want to update my IE browser in by project to IE 10, so the value vould be 10001.
    My applications' exe is called Uranium.exe
    shall I put the command:

    FixBrowserVersion("Uranium.exe", 10001) in the _OnLoad event of my form?

    In this case, it did not work

    In case it may help... when i say it does not work i mean that when i go to the detectmybrowser.com website i get this answer:

    You're using Mozilla version 11 on Windows

  9. #9

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

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

    I do not know why it is telling you, you are using Mozilla. However I found that the detectmyborwser website isn't accurate, first off. Thus, you are only going to be emulating IE11 as IE7 is at the core of the webbrowser control no matter how much you try the core version of the control is IE7. I couldn't find a way to go to a specific version tbh, that part never worked, it only will take you to the latest IE which is installed, on my machine its IE 11
    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.

  10. #10
    New Member
    Join Date
    Apr 2018
    Location
    Rome, Italy
    Posts
    3

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

    Quote Originally Posted by jdc20181 View Post
    I do not know why it is telling you, you are using Mozilla. However I found that the detectmyborwser website isn't accurate, first off. Thus, you are only going to be emulating IE11 as IE7 is at the core of the webbrowser control no matter how much you try the core version of the control is IE7. I couldn't find a way to go to a specific version tbh, that part never worked, it only will take you to the latest IE which is installed, on my machine its IE 11
    Thank you JDC, in my pc i have IE 11 as well, on windows 7 home 64x.
    I have tried the class again... if i run the project from inside visual studio i get a feedback as being using Mozilla, if i run the executable in the BIN / DEBUG folder of the project, I get a feedback like being using IE7. Eventually i have tried to load the whatsappweb website, which does not work on IE7 but works on IE10 and IE11, and in my executable does not work. I get a message to upload to a more recent version of IE.
    I have tried all 'grammars' for the class:

    WebBrowserHelper.FixBrowserVersion()
    WebBrowserHelper.FixBrowserVersion("Uranium.exe")
    WebBrowserHelper.FixBrowserVersion("Uranium.exe", 11001) (using also the codes for IE9 and IE10

    the result is the same.
    I wonder how could the MSDN website offer the same solution when it actually does not work...

  11. #11

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

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

    I had it work for me, but it was using an older version of the .net framework it could be its depreciated I will have to test it further, and get back with you.
    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.

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


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.