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

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
    974

    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!!
    Last edited by jdc20181; Nov 7th, 2016 at 04:59 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
    974

    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.

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.