c#에서 webbrowser 적용시 Internet explorer의 버전 올리기 [현재 시스템에서 사용중인 버전으로 수정하기]
기본적으로 시샵에서 Internet Explorer 7 버전이 탑재되어 있어요
몇년도에 만들어진 버전인지 모르지만 아주 오래된 버전이고, 현재 시점에는 Internet Explorer 11점 대가 사용되고 있어요
수정하기 위해서는 레지스트리 값을 수정해 주셔야 해요
소스)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
//웹브라우저 레지스트리 등록하는 부분
//(x) http://guideme.tistory.com/1
//(ㅇ) http://okgood0412.tistory.com/entry/C-WebBrowser-version-%EB%B3%80%EA%B2%BD
using System.Security;
using Microsoft.Win32;
using System.IO;
using System.Threading;
using System.Diagnostics;
namespace Test5
{
static class Program
{
static Mutex mutex = new System.Threading.Mutex(false, "jMutex");
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
//SetBrowserEmulationVersion();
if (!mutex.WaitOne(TimeSpan.FromSeconds(2), false))
{
//another application instance is running
return;
}
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var targetApplication = Process.GetCurrentProcess().ProcessName + ".exe";
int browserver = 7;
int ie_emulation = 11999;
using (WebBrowser wb = new WebBrowser())
{
browserver = wb.Version.Major;
if (browserver >= 11)
ie_emulation = 11001;
else if (browserver == 10)
ie_emulation = 10001;
else if (browserver == 9)
ie_emulation = 9999;
else if (browserver == 8)
ie_emulation = 8888;
else
ie_emulation = 7000;
}
try
{
//string tmp = Properties.Settings.Default.Properties.
SetIEVersioneKeyforWebBrowserControl(targetApplication, ie_emulation);
Application.Run(new Form1());
}
catch (Exception ex1)
{
}
}
catch (Exception ex2)
{
}
finally
{
mutex.ReleaseMutex();
}
}
private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval)
{
RegistryKey Regkey = null;
try
{
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
//If the path is not correct or
//If user't have priviledges to access registry
if (Regkey == null)
{
MessageBox.Show("Application FEATURE_BROWSER_EMULATION Failed - Registry key Not found");
return;
}
string FindAppkey = Convert.ToString(Regkey.GetValue(appName));
//Check if key is already present
if (FindAppkey == ieval.ToString())
{
MessageBox.Show("Application FEATURE_BROWSER_EMULATION already set to " + ieval);
Regkey.Close();
return;
}
//If key is not present or different from desired, add/modify the key , key value
Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord);
//check for the key after adding
FindAppkey = Convert.ToString(Regkey.GetValue(appName));
if (FindAppkey == ieval.ToString())
{
MessageBox.Show("Application FEATURE_BROWSER_EMULATION changed to " + ieval + "; changes will be visible at application restart");
}
else
{
MessageBox.Show("Application FEATURE_BROWSER_EMULATION setting failed; current value is " + ieval);
}
}
catch (Exception ex)
{
MessageBox.Show("Application FEATURE_BROWSER_EMULATION setting failed; " + ex.Message);
}
finally
{
//Close the Registry
if (Regkey != null)
Regkey.Close();
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
} // end main();
}
}
댓글 없음:
댓글 쓰기