龙空技术网

C#得到及清空浏览器记录

逍遥总遥 221

前言:

如今兄弟们对“删除ie浏览器历史记录中的所有内容的操作步骤”大约比较注意,朋友们都想要剖析一些“删除ie浏览器历史记录中的所有内容的操作步骤”的相关知识。那么小编也在网络上网罗了一些有关“删除ie浏览器历史记录中的所有内容的操作步骤””的相关文章,希望你们能喜欢,姐妹们快快来学习一下吧!

下面是一个用C#操作用户浏览器记录的方法,包括得到这些记录,及清空它们的方法

using System.Collections;using System.Runtime.InteropServices;using System.Runtime.InteropServices.ComTypes;namespace WinFormsApp1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        IEHistory ie = new IEHistory();        private void button1_Click(object sender, EventArgs e)        {            //得到记录            string[] r = ie.GetIEHistory();            MessageBox.Show(string.Join(',', r));        }        private void button2_Click(object sender, EventArgs e)        {            //清空            string r = ie.ClearIEHistory();            MessageBox.Show(r);        }        /// <summary>        /// 浏览器历史记录        /// </summary>        public class IEHistory        {            /// <summary>            /// 清空浏览历史记录            /// </summary>            public string ClearIEHistory()            {                try                {                    IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2)new UrlHistory();                    vUrlHistoryStg2.ClearHistory();                    return "OK";                }                catch (Exception ErrMsg)                {                    return ErrMsg.ToString();                }            }            /// <summary>            /// 得到浏览历史记录            /// </summary>            /// <returns></returns>            public string[] GetIEHistory()            {                ArrayList al = new ArrayList();                IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2)new UrlHistory();                IEnumSTATURL vEnumSTATURL = vUrlHistoryStg2.EnumUrls();                STATURL vSTATURL;                uint vFectched;                while (vEnumSTATURL.Next(1, out vSTATURL, out vFectched) == 0)                {                    string src = vSTATURL.pwcsUrl;                    al.Add(src);                }                return (string[])al.ToArray(typeof(string));            }            #region 不需要改动            struct STATURL            {                public static uint SIZEOF_STATURL =                    (uint)Marshal.SizeOf(typeof(STATURL));                public uint cbSize;                [MarshalAs(UnmanagedType.LPWStr)]                public string pwcsUrl;                [MarshalAs(UnmanagedType.LPWStr)]                public string pwcsTitle;                public FILETIME ftLastVisited,                    ftLastUpdated,                    ftExpires;                public uint dwFlags;            }            [ComImport, Guid("3C374A42-BAE4-11CF-BF7D-00AA006946EE"),                InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]            interface IEnumSTATURL            {                [PreserveSig]                uint Next(uint celt, out STATURL rgelt, out uint pceltFetched);                void Skip(uint celt);                void Reset();                void Clone(out IEnumSTATURL ppenum);                void SetFilter(                    [MarshalAs(UnmanagedType.LPWStr)] string poszFilter,                    uint dwFlags);            }            [ComImport, Guid("AFA0DC11-C313-11d0-831A-00C04FD5AE38"),                InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]            interface IUrlHistoryStg2            {                #region IUrlHistoryStg methods                void AddUrl(                    [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,                    [MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,                    uint dwFlags);                void DeleteUrl(                    [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,                    uint dwFlags);                void QueryUrl(                    [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,                    uint dwFlags,                    ref STATURL lpSTATURL);                void BindToObject(                    [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,                    ref Guid riid,                    [MarshalAs(UnmanagedType.IUnknown)] out object ppvOut);                IEnumSTATURL EnumUrls();                #endregion                void AddUrlAndNotify(                    [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,                    [MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,                    uint dwFlags,                    [MarshalAs(UnmanagedType.Bool)] bool fWriteHistory,                    [MarshalAs(UnmanagedType.IUnknown)] object /*IOleCommandTarget*/                    poctNotify,                    [MarshalAs(UnmanagedType.IUnknown)] object punkISFolder);                void ClearHistory();            }            [ComImport, Guid("3C374A40-BAE4-11CF-BF7D-00AA006946EE")]            class UrlHistory /* : IUrlHistoryStg[2] */ { }            #endregion        }    }}
注意:using System.Runtime.InteropServices;这个文件可能会提示下载新版本。

标签: #删除ie浏览器历史记录中的所有内容的操作步骤 #怎么删除ie浏览器历史记录文件