Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Diagnostics;
  4. using System.Security.Permissions;
  5. using Microsoft.Win32;
  6.  
  7. [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
  8.  
  9. public class Program : Form
  10.  
  11. private WebBrowser webBrowser;
  12.  
  13. public Program()
  14. {
  15. InitialiseForm();
  16. }
  17.  
  18. public void InitialiseForm()
  19. {
  20. webBrowser = new WebBrowser();
  21. Controls.AddRange(new Control[] {webBrowser});
  22. webBrowser.ScriptErrorsSuppressed = true;
  23. webBrowser.Dock = DockStyle.Fill;
  24.  
  25. webBrowser.Navigate("http://www.nationalgeographic.com/");
  26.  
  27. }
  28.  
  29. [STAThread]
  30.  
  31. public static void Main()
  32. {
  33. Application.EnableVisualStyles();
  34. Application.Run(new Program());
  35. }
  36.  
  37. private void Form1_Load(object sender, EventArgs e)
  38. {
  39. var appName = Process.GetCurrentProcess().ProcessName + ".exe";
  40. SetIE8KeyforWebBrowserControl(appName);
  41. }
  42.  
  43. private void SetIE8KeyforWebBrowserControl(string appName)
  44. {
  45. RegistryKey Regkey = null;
  46. try
  47. {
  48. // For 64 bit machine
  49. //if (Environment.Is64BitOperatingSystem)
  50. //Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", true);
  51.  
  52. //else
  53. //For 32 bit machine
  54. Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
  55.  
  56.  
  57. // If the path is not correct or
  58. // if the user haven't priviledges to access the registry
  59. if (Regkey == null)
  60. {
  61. MessageBox.Show("Application Settings Failed - Address Not found");
  62. return;
  63. }
  64.  
  65. string FindAppkey = Convert.ToString(Regkey.GetValue(appName));
  66.  
  67. // Check if key is already present
  68. if (FindAppkey == "8000")
  69. {
  70. MessageBox.Show("Required Application Settings Present");
  71. Regkey.Close();
  72. return;
  73. }
  74.  
  75. // If a key is not present add the key, Key value 8000 (decimal)
  76. if (string.IsNullOrEmpty(FindAppkey))
  77. Regkey.SetValue(appName, unchecked((int)0x1F40), RegistryValueKind.DWord);
  78.  
  79. // Check for the key after adding
  80. FindAppkey = Convert.ToString(Regkey.GetValue(appName));
  81.  
  82. if (FindAppkey == "8000")
  83. MessageBox.Show("Application Settings Applied Successfully");
  84. else
  85. MessageBox.Show("Application Settings Failed, Ref: " + FindAppkey);
  86. }
  87. catch (Exception ex)
  88. {
  89. MessageBox.Show("Application Settings Failed");
  90. MessageBox.Show(ex.Message);
  91. }
  92. finally
  93. {
  94. // Close the Registry
  95. if (Regkey != null)
  96. Regkey.Close();
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement