Projekt-Anfragen: Tel: 07022/9319004 info@CodeDocu.de Software Entwicklung in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

WinForms, C#: Einträge in der Registry für den Internetexplorer und webBrowser erstellen
 
Beim Verwenden des Webbrowser Controls in einer Microsoft Office Anwendung kann es oft vorkommen, dass die scripte auf Webseiten zu Fehlern führen.
Das Webbrowser Control basiert auf dem Internetexplorer und bezieht auch hieraus seine Zugriffsrechte und Einstellungen.
Um diese zu erweitern muss man in der Registry Erweiterungen vornehmen.
 
Mit dem folgenden Code in C# werden die notwendigen Eintragungen vorgenommen. In diesem Fall handelt es sich um eine WinWord.exe Anwendung, welche als das Webbrowser Control in einer Windows Forms Anwendung aufruft.

 
 
 
C# Code zum Erstellen von Einträgen im Internetexplorer in der Registry als Word Application
Der originale Code wird unter NeoWin.net geführt allerdings in vb.net.
https://www.neowin.net/forum/topic/1077469-vbnet-webbrowser-control-does-not-load-javascript/
 
Leider hat der vorgeschlagenen C# Code zu keiner Lösung des gezeigten Problems mit der Verwendung der Webseite translate.google.com geführt.
Dennoch ist der Code geeignet um darzustellen, wie man mit C# Eintragungen in der Windows Registry vornehmen kann.

 
#region "======< IE Fix >====="
private void btnInit_IE_Click(object sender, EventArgs e)
{
fix_IE_Browser_Control();
}
 
 
private void fix_IE_Browser_Control()
{
//http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx Date: 2014
//https://www.neowin.net/forum/topic/1077469-vbnet-webbrowser-control-does-not-load-javascript/
 
// FeatureControl settings are per-process
string fileName = System.IO.Path.GetFileName(Application.ExecutablePath);
 
SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode());
 
// Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
SetBrowserFeatureControlKey("FEATURE_AJAX_CONNECTIONEVENTS", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_MANAGE_script_CIRCULAR_REFS", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_DOMSTORAGE ", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_GPU_RENDERING ", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI ", fileName, 0);
SetBrowserFeatureControlKey("FEATURE_DISABLE_LEGACY_COMPRESSION", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_LOCALMACHINE_LOCKDOWN", fileName, 0);
SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_OBJECT", fileName, 0);
SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_script", fileName, 0);
SetBrowserFeatureControlKey("FEATURE_DISABLE_NAVIGATION_SOUNDS", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_scriptURL_MITIGATION", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_SPELLCHECKING", fileName, 0);
SetBrowserFeatureControlKey("FEATURE_STATUS_BAR_THROTTLING", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_TABBED_BROWSING", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_VALIDATE_NAVIGATE_URL", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_WEBOC_DOCUMENT_ZOOM", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_WEBOC_POPUPMANAGEMENT", fileName, 0);
SetBrowserFeatureControlKey("FEATURE_WEBOC_MOVESIZECHILD", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_ADDON_MANAGEMENT", fileName, 0);
SetBrowserFeatureControlKey("FEATURE_WEBSOCKET", fileName, 1);
SetBrowserFeatureControlKey("FEATURE_WINDOW_RESTRICTIONS ", fileName, 0);
SetBrowserFeatureControlKey("FEATURE_XMLHTTP", fileName, 1);
}
 
private void SetBrowserFeatureControlKey(string feature, string appName, uint value)
{
//--------< SetBrowserFeatureControlKey() >--------
if (Environment.Is64BitOperatingSystem)
{
set_reg_key("Software\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\", feature, appName, value);
set_reg_key("Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\", feature, appName, value);
}
//--------</ SetBrowserFeatureControlKey() >-----
}
 
private void set_reg_key(string string_key, string feature, string appName, uint value)
{
//--------< set_reg_key() >-----
RegistryKey key = Registry.LocalMachine.CreateSubKey(String.Concat(string_key, feature), RegistryKeyPermissionCheck.ReadWriteSubTree);
key.SetValue(appName, Convert.ToUInt32(value), RegistryValueKind.DWord);
//--------</ set_reg_key() >-----
}
 
//--------</ SetBrowserFeatureControlKey() >--------
 
 
 
 
 
private UInt32 GetBrowserEmulationMode()
{
//--------< GetBrowserEmulationMode() >-----
int browserVersion = 7;
RegistryKey ieKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer", RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.QueryValues);
var version = ieKey.GetValue("svcVersion");
if (version == null)
{
version = ieKey.GetValue("Version");
if (version == null)
{
throw new Exception("Microsoft Internet Explorer is required!");
}
}
string sVersion = version.ToString();
browserVersion = Convert.ToInt32(sVersion.Substring(0, sVersion.IndexOf(".")));
//Integer.TryParse(version.ToString().Split("."c)(0), browserVersion);
 
 
UInt32 mode = 10000;
// Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
switch (browserVersion)
{
//Select Case browserVersion
case 7:
mode = 7000;
// Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
break;
case 8:
mode = 8000;
// Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8;
break;
case 9:
mode = 9000;
// Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
break;
case 10:
mode = 10000;
// Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
break;
case 11:
mode = 11001;
// Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
break;
default:
// use IE10 mode by default
break;
}
 
return mode;
//--------</ GetBrowserEmulationMode() >-----
}
#endregion "======</ IE Fix >====="
 
 

 
Mobile
»
Winforms: Lokale Datenbank, erstellen, anbinden, anzeigen, Insert Update, Delete
»
WinForms, C#: Einträge in der Registry für den Internetexplorer und webBrowser erstellen
»
WPF Control innerhalb einer WinForms Anwendung
»
Wie öffnet man in C# WinForms ein zweites Formular?
»
Wie kopiert man ein Formular in Microsoft Winforms

.

Jobs, Projekte, Angebote für Freiberufler, Selbstständig an Info@CodeDocu.de