🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / internet explorer ie son versiyon kullanmak için yapılacak adimlar

1-) C# RMOS - internet explorer ie son versiyon kullanmak için yapılacak adimlar

kaynak : https://stackoverflow.com/questions/17922308/use-latest-version-of-internet-explorer-in-the-webbrowser-control

 

1-) C# RMOS - WebBrowserHelper.cs

 

using System;

 

namespace RM_Novum

{

    // webbrowser son versiyon kaynak https://stackoverflow.com/questions/17922308/use-latest-version-of-internet-explorer-in-the-webbrowser-control

    class WebBrowserHelper

    {

        public static int GetEmbVersion()

        {

            int ieVer = GetBrowserVersion();

 

            if (ieVer > 9)

                return ieVer * 1000 + 1;

 

            if (ieVer > 7)

                return ieVer * 1111;

 

            return 7000;

        } // End Function GetEmbVersion

 

        public static void FixBrowserVersion()

        {

            string appName = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location);

            FixBrowserVersion(appName);

        }

 

        public static void FixBrowserVersion(string appName)

        {

            FixBrowserVersion(appName, GetEmbVersion());

        } // End Sub FixBrowserVersion

 

        // FixBrowserVersion("<YourAppName>", 9000);

        public static void FixBrowserVersion(string appName, int ieVer)

        {

            FixBrowserVersion_Internal("HKEY_LOCAL_MACHINE", appName + ".exe", ieVer);

            FixBrowserVersion_Internal("HKEY_CURRENT_USER", appName + ".exe", ieVer);

            FixBrowserVersion_Internal("HKEY_LOCAL_MACHINE", appName + ".vshost.exe", ieVer);

            FixBrowserVersion_Internal("HKEY_CURRENT_USER", appName + ".vshost.exe", ieVer);

        } // End Sub FixBrowserVersion

 

        private static void FixBrowserVersion_Internal(string root, string appName, int ieVer)

        {

            try

            {

                //For 64 bit Machine

                if (Environment.Is64BitOperatingSystem)

                    Microsoft.Win32.Registry.SetValue(root + @"\Software\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", appName, ieVer);

                else  //For 32 bit Machine

                    Microsoft.Win32.Registry.SetValue(root + @"\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", appName, ieVer);

 

 

            }

            catch (Exception)

            {

                // some config will hit access rights exceptions

                // this is why we try with both LOCAL_MACHINE and CURRENT_USER

            }

        } // End Sub FixBrowserVersion_Internal

 

        public static int GetBrowserVersion()

        {

            // string strKeyPath = @"HKLM\SOFTWARE\Microsoft\Internet Explorer";

            string strKeyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer";

            string[] ls = new string[] { "svcVersion", "svcUpdateVersion", "Version", "W2kVersion" };

 

            int maxVer = 0;

            for (int i = 0; i < ls.Length; ++i)

            {

                object objVal = Microsoft.Win32.Registry.GetValue(strKeyPath, ls[i], "0");

                string strVal = System.Convert.ToString(objVal);

                if (strVal != null)

                {

                    int iPos = strVal.IndexOf('.');

                    if (iPos > 0)

                        strVal = strVal.Substring(0, iPos);

 

                    int res = 0;

                    if (int.TryParse(strVal, out res))

                        maxVer = Math.Max(maxVer, res);

                } // End if (strVal != null)

 

            } // Next i

 

            return maxVer;

        } // End Function GetBrowserVersion

    }

}

 

 

2-) Form1.cs

 

using Microsoft.Win32;

using System;

using System.Diagnostics;

using System.Windows.Forms;

 

namespace RM_Novum

{

    public partial class Form1 : Form

    {

        // https://stackoverflow.com/questions/17922308/use-latest-version-of-internet-explorer-in-the-webbrowser-control

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            var appName = Process.GetCurrentProcess().ProcessName + ".exe";

            SetIE8KeyforWebBrowserControl(appName);

            WebBrowserHelper.FixBrowserVersion();

        }

 

        private void btnRezervasyonGetir_Click(object sender, EventArgs e)

        {

            webBrowser1.Navigate("http://hotels.novum.com.tr/index.php");

 

        }

        private void SetIE8KeyforWebBrowserControl(string appName)

        {

            RegistryKey Regkey = null;

            try

            {

                // For 64 bit machine

                if (Environment.Is64BitOperatingSystem)

                    Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);

                else  //For 32 bit machine

                    Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);

 

                // If the path is not correct or

                // if the user haven't priviledges to access the registry

                if (Regkey == null)

                {

                    MessageBox.Show("Application Settings Failed - Address Not found");

                    return;

                }

 

                string FindAppkey = Convert.ToString(Regkey.GetValue(appName));

 

                // Check if key is already present

                if (FindAppkey == "8000")

                {

                    MessageBox.Show("Required Application Settings Present");

                    Regkey.Close();

                    return;

                }

 

                // If a key is not present add the key, Key value 8000 (decimal)

                if (string.IsNullOrEmpty(FindAppkey))

                    Regkey.SetValue(appName, unchecked((int)0x1F40), RegistryValueKind.DWord);

 

                // Check for the key after adding

                FindAppkey = Convert.ToString(Regkey.GetValue(appName));

 

                if (FindAppkey == "8000")

                    MessageBox.Show("Application Settings Applied Successfully");

                else

                    MessageBox.Show("Application Settings Failed, Ref: " + FindAppkey);

            }

            catch (Exception ex)

            {

                MessageBox.Show("Application Settings Failed");

                MessageBox.Show(ex.Message);

            }

            finally

            {

                // Close the Registry

                if (Regkey != null)

                    Regkey.Close();

            }

        }

    }

}

 

 2021 Ocak 18 Pazartesi
 368