| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using System;
- using Microsoft.Win32;
- using System.Windows.Forms;
- using Excel;
- namespace Core.Mes.Client.Common
- {
- public partial class frmIEBrowser : Form
- {
- struct regkey
- {
- public RegistryKey rootKey;
- public string sKey;
- public string sItem;
- public int val;
- public bool isExist;
- }
- regkey[] aryKeys = new regkey[10];
- public frmIEBrowser()
- {
- InitializeComponent();
- }
- void RegSet()
- {
- try
- {
- //RegistryPermission f = new RegistryPermission(RegistryPermissionAccess.Read | RegistryPermissionAccess.Write,
- // "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes");
- //f.AddPathList(RegistryPermissionAccess.Read | RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT");
- RegistryKey rKey = Registry.LocalMachine;
- aryKeys[0].rootKey = rKey;
- aryKeys[0].sKey = "SOFTWARE\\Classes\\Excel.Sheet.12";
- aryKeys[0].isExist = false;
- aryKeys[0].sItem = "BrowserFlags";
- RegistryKey subKey = rKey.OpenSubKey(aryKeys[0].sKey, true);
- if (subKey != null)
- {
- if (subKey.GetValue(aryKeys[0].sItem, null) != null)
- {
- aryKeys[0].val = (int)subKey.GetValue(aryKeys[0].sItem);
- aryKeys[0].isExist = true;
- subKey.SetValue(aryKeys[0].sItem, -(0xFFFFFFFF - 0x80000A00 + 1), RegistryValueKind.DWord);
- subKey.Close();
- aryKeys[1].rootKey = rKey;
- aryKeys[1].sKey = "SOFTWARE\\Classes\\Excel.Sheet.8";
- aryKeys[1].isExist = false;
- aryKeys[1].sItem = "BrowserFlags";
- subKey = rKey.OpenSubKey(aryKeys[1].sKey, true);
- if (subKey != null)
- {
- aryKeys[1].val = (int)subKey.GetValue(aryKeys[1].sItem);
- aryKeys[1].isExist = true;
- subKey.SetValue(aryKeys[1].sItem, -(0xFFFFFFFF - 0x80000A00 + 1), RegistryValueKind.DWord);
- subKey.Close();
- }
- aryKeys[2].rootKey = rKey;
- aryKeys[2].sKey = "SOFTWARE\\Classes\\Excel.SheetMacroEnabled.12";
- aryKeys[2].isExist = false;
- aryKeys[2].sItem = "BrowserFlags";
- subKey = rKey.OpenSubKey(aryKeys[2].sKey, true);
- if (subKey != null)
- {
- aryKeys[2].val = (int)subKey.GetValue(aryKeys[2].sItem);
- aryKeys[2].isExist = true;
- subKey.SetValue(aryKeys[2].sItem, -(0xFFFFFFFF - 0x80000A00 + 1), RegistryValueKind.DWord);
- subKey.Close();
- }
- aryKeys[3].rootKey = rKey;
- aryKeys[3].sKey = "SOFTWARE\\Classes\\Excel.SheetBinaryMacroEnabled.12";
- aryKeys[3].isExist = false;
- aryKeys[3].sItem = "BrowserFlags";
- subKey = rKey.OpenSubKey(aryKeys[3].sKey, true);
- if (subKey != null)
- {
- aryKeys[3].val = (int)subKey.GetValue(aryKeys[3].sItem);
- aryKeys[3].isExist = true;
- subKey.SetValue(aryKeys[3].sItem, -(0xFFFFFFFF - 0x80000A00 + 1), RegistryValueKind.DWord);
- subKey.Close();
- }
- }
- }
- rKey.Close();
- rKey = Registry.ClassesRoot;
- aryKeys[4].rootKey = rKey;
- aryKeys[4].sKey = "Excel.Sheet.8";
- aryKeys[4].isExist = false;
- aryKeys[4].sItem = "EditFlags";
- subKey = rKey.OpenSubKey(aryKeys[4].sKey, true);
- if (subKey != null)
- {
- if (!(subKey.GetValue(aryKeys[4].sItem) is Array))
- aryKeys[4].val = (int)subKey.GetValue(aryKeys[4].sItem);
- else
- aryKeys[4].val = BitConverter.ToInt32((byte[])subKey.GetValue(aryKeys[4].sItem), 0);
- aryKeys[4].isExist = true;
- subKey.SetValue(aryKeys[4].sItem, 0x0010000, RegistryValueKind.DWord);
- subKey.Close();
- }
- rKey.Close();
- }
- catch (Exception ee)
- {
- MessageBox.Show(ee.Message);
- }
- }
- void RegBack()
- {
- try
- {
- RegistryKey rKey, subKey;
- //if (aryKeys[0].isExist)
- //{
- // rKey = Registry.LocalMachine;
- // subKey = rKey.OpenSubKey(aryKeys[0].sKey, true);
- //}
- for (int i = 0; i < aryKeys.Length; i++)
- {
- if (aryKeys[i].isExist)
- {
- rKey = aryKeys[i].rootKey;
- subKey = rKey.OpenSubKey(aryKeys[i].sKey, true);
- subKey.SetValue(aryKeys[i].sItem, aryKeys[i].val, RegistryValueKind.DWord);
- subKey.Close();
- rKey.Close();
- }
- }
- }
- catch { }
- }
- public string sUrl = "";
- void Go()
- {
- Object obj = new object();
- axWebBrowser1.Navigate(sUrl, ref obj, ref obj, ref obj, ref obj);
- }
- private void frmIEBrowser_Load(object sender, EventArgs e)
- {
- RegSet();
- Go();
- }
- private void frmIEBrowser_FormClosing(object sender, FormClosingEventArgs e)
- {
- RegBack();
- try
- {
- object sRef = new object();
- axWebBrowser1.Navigate("about:blank", ref sRef, ref sRef, ref sRef, ref sRef);
- axWebBrowser1.Dispose();
- }
- catch { }
- }
- public Excel.Application xlApp;
- public Excel.Workbook xlWb;
- private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
- {
- if (axWebBrowser1.Document is Excel.Workbook)
- {
- xlWb = (axWebBrowser1.Document as Excel.Workbook);
- xlApp = xlWb.Application;
- xlApp.DisplayFormulaBar = false;
- xlApp.DisplayAlerts = false;
- }
- }
- }
- }
|