标签:OpenSubKey 缓存 C# key64 SW key null IE Microsoft
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace LIZH { /// <summary> /// IE注册管理 /// </summary> public class IERegeditManager { public static void RegeditIE11() { try { //\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine .OpenSubKey(@"SOFTWARE"); if (key != null) key = key.OpenSubKey(@"Microsoft"); if (key != null) key = key.OpenSubKey(@"Internet Explorer"); if (key != null) key = key.OpenSubKey(@"Main"); if (key != null) key = key.OpenSubKey(@"FeatureControl"); if (key != null) { key = key.OpenSubKey(@"FEATURE_BROWSER_EMULATION", true); if (key != null) { var efs = key.GetValue("EFSProConsole.exe"); if (efs == null) { key.SetValue("EFSProConsole.exe", 11001, Microsoft.Win32.RegistryValueKind.DWord); //调试运行需要加上,否则不起作用 key.SetValue("EFSProConsole.vshost.exe", 11001, Microsoft.Win32.RegistryValueKind.DWord); } } } //\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION Microsoft.Win32.RegistryKey key64 = Microsoft.Win32.Registry.LocalMachine .OpenSubKey(@"SOFTWARE"); if (key64 != null) key64 = key64.OpenSubKey(@"WOW6432Node"); if (key64 != null) key64 = key64.OpenSubKey(@"Microsoft"); if (key64 != null) key64 = key64.OpenSubKey(@"Internet Explorer"); if (key64 != null) key64 = key64.OpenSubKey(@"Main"); if (key64 != null) key64 = key64.OpenSubKey(@"FeatureControl"); if (key64 != null) { key64 = key64.OpenSubKey(@"FEATURE_BROWSER_EMULATION", true); if (key64 != null) { var efs = key64.GetValue("EFSProConsole.exe"); if (efs == null) { key64.SetValue("EFSProConsole.exe", 11001, Microsoft.Win32.RegistryValueKind.DWord); //调试运行需要加上,否则不起作用 key64.SetValue("EFSProConsole.vshost.exe", 11001, Microsoft.Win32.RegistryValueKind.DWord); } } } } catch (Exception) { } } /// <summary> /// 清除IE缓存 /// </summary> public static void ClearIECache() { var specialFolders = new List<Environment.SpecialFolder>() { Environment.SpecialFolder.InternetCache, Environment.SpecialFolder.Cookies, Environment.SpecialFolder.History, }; foreach (var item in specialFolders) { try { var directory = new DirectoryInfo(Environment.GetFolderPath(item)); ClearFolder(directory); } catch (Exception ex) { } } } private static void ClearFolder(DirectoryInfo folder) { foreach (FileInfo file in folder.GetFiles()) { if (File.Exists(file.FullName)) { try { file.Delete(); } catch (Exception ex) { } } } foreach (DirectoryInfo directory in folder.GetDirectories()) { if (Directory.Exists(directory.FullName)) { var security = new System.Security.AccessControl.DirectorySecurity(); var windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent(); if (windowsIdentity != null) { var id = windowsIdentity.User; var rule = new System.Security.AccessControl.FileSystemAccessRule(id, System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow); security.AddAccessRule(rule); directory.SetAccessControl(security); } ClearFolder(directory); } } } /// <summary> /// 清除IE缓存 /// </summary> /// <param name="hwnd"></param> /// <param name="lpOperation"></param> /// <param name="lpFile"></param> /// <param name="lpParameters"></param> /// <param name="lpDirectory"></param> /// <param name="nShowCmd"></param> /// <returns></returns> [DllImport("shell32.dll")] public static extern IntPtr ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, ShowCommands nShowCmd); } public enum ShowCommands : int { SW_HIDE = 0, SW_SHOWNORMAL = 1, SW_NORMAL = 1, SW_SHOWMINIMIZED = 2, SW_SHOWMAXIMIZED = 3, SW_MAXIMIZE = 3, SW_SHOWNOACTIVATE = 4, SW_SHOW = 5, SW_MINIMIZE = 6, SW_SHOWMINNOACTIVE = 7, SW_SHOWNA = 8, SW_RESTORE = 9, SW_SHOWDEFAULT = 10, SW_FORCEMINIMIZE = 11, SW_MAX = 11 } }
搜索
复制
标签:OpenSubKey,缓存,C#,key64,SW,key,null,IE,Microsoft 来源: https://www.cnblogs.com/lizhenhong/p/16450934.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。