private void GetHistory() { IUrlHistoryStg2 _UrlHistoryStg2 = (IUrlHistoryStg2) new UrlHistory(); IEnumSTATURL _EnumSTATURL = _UrlHistoryStg2.EnumUrls(); STATURL _STATURL; uint _Fectched; DateTime Datetime; int count = 0; FileStream NoteFile = new FileStream("C:\\Users\\oceanier\\Desktop\\BrowserHistory.txt", FileMode.Create, FileAccess.Write);//创建写入文件 StreamWriter WriteNote = new StreamWriter(NoteFile); WriteNote.WriteLine("序号\t访问时间\t\t网址\n"); while (_EnumSTATURL.Next(1, out _STATURL, out _Fectched) == 0) { if (_STATURL.pwcsUrl.Substring(0, 4) == "http" && _STATURL.pwcsUrl.Length <= 100) { count += 1; Datetime = FileTimeToDatetime(_STATURL.ftLastVisited); richTextBox1.AppendText(string.Format("{0}\r\n{1}\r\n{2}\r\n", count, Datetime, _STATURL.pwcsUrl)); WriteNote.WriteLine(count + "\t" + Datetime + "\t" + _STATURL.pwcsUrl + "\n"); } } MessageBox.Show("成功获取浏览器浏览记录!\n可在桌面txt文档中查看。", "提示"); }
/// <summary> /// /// </summary> /// <returns></returns> public static List <UrlData> GetUrlData() { ////定义注册表顶级节点 其命名空间是using Microsoft.Win32; //RegistryKey historykey; ////检索当前用户CurrentUser子项Software\\Microsoft\\Internet Explorer\\typedURLs //historykey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\typedURLs", true); //if (historykey != null) //{ // //获取检索的所有值 // String[] names = historykey.GetValueNames(); // foreach (String str in names) // { // txtUrl.Items.Add(historykey.GetValue(str).ToString()); // } //} var STATURL = new List <UrlData>(); IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2) new UrlHistory(); IEnumSTATURL vEnumSTATURL = vUrlHistoryStg2.EnumUrls(); STATURL vSTATURL; uint vFectched; while (vEnumSTATURL.Next(1, out vSTATURL, out vFectched) == 0) { STATURL.Add(new UrlData() { Name = vSTATURL.pwcsTitle, Url = vSTATURL.pwcsUrl, }); //richTextBox1.AppendText(string.Format("{0}\r\n{1}\r\n", vSTATURL.pwcsTitle, vSTATURL.pwcsUrl)); //txtUrl.Items.Add(string.Format("{0}\r\n{1}\r\n", vSTATURL.pwcsTitle, vSTATURL.pwcsUrl)); } return(STATURL); }
//浏览记录,先读IE的然后读当前的 private void viewHistory_Load(object sender, EventArgs e) { IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2) new UrlHistory(); IEnumSTATURL vEnumSTATURL = vUrlHistoryStg2.EnumUrls(); STATURL vSTATURL; uint vFectched; while (vEnumSTATURL.Next(1, out vSTATURL, out vFectched) == 0) { listBox1.Items.Add(string.Format("{0}\r\n{1}\r\n", vSTATURL.pwcsTitle, vSTATURL.pwcsUrl)); } }
private void button1_Click(object sender, EventArgs e) { IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2) new UrlHistory(); IEnumSTATURL vEnumSTATURL = vUrlHistoryStg2.EnumUrls(); STATURL vSTATURL; uint vFectched; while (vEnumSTATURL.Next(1, out vSTATURL, out vFectched) == 0) { //richTextBox1.AppendText(string.Format("{0}:{1}\r\n", vSTATURL.pwcsTitle, vSTATURL.pwcsUrl)); } //vUrlHistoryStg2.ClearHistory();//清除历史 }
/// <summary> /// 获取IE最近访问记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { //********************************************************************** // 第二种方法参照:http://blog.sina.com.cn/s/blog_589d32f5010007xf.html // 参考资料: // http://social.msdn.microsoft.com/Forums/windows/zh-CN/89cfff57-8f84-4b9d-a7a8-bc3aad6e0196/browsing-history // http://bbs.csdn.net/topics/290070046 // http://hi.baidu.com/wayright/item/8af0f88a59aca157e63d19f2 // http://stackoverflow.com/questions/4305757/iurlhistorystg2clearhistory-does-not-work-from-a-service //************************************************************************ try { //清空listBox listBox1.Items.Clear(); //定义变量 IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2) new UrlHistory(); IEnumSTATURL vEnumSTATURL = vUrlHistoryStg2.EnumUrls(); STATURL vSTATURL; uint vFectched; Int64 number = 1; //记录URL标号 //循环获取IE浏览器记录 while (vEnumSTATURL.Next(1, out vSTATURL, out vFectched) == 0) { //添加网址的标题 if (vSTATURL.pwcsTitle == null) { listBox1.Items.Add(string.Format("第{0}条 无标题", number)); } else { listBox1.Items.Add(string.Format("第{0}条 {1}", number, vSTATURL.pwcsTitle)); } //添加URL listBox1.Items.Add(string.Format("{0}", vSTATURL.pwcsUrl)); //换行 listBox1.Items.Add(" "); number++; } if (number == 1) { MessageBox.Show(this, "IE历史记录已经删空", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception msg) //异常处理 { MessageBox.Show(msg.Message); } }
static void Main(string[] args) { IUrlHistoryStg2 uhs2 = (IUrlHistoryStg2) new UrlHistory(); IEnumSTATURL estaturl = uhs2.EnumUrls(); STATURL staturl; uint fetched; while (0 == estaturl.Next(1, out staturl, out fetched)) { Console.WriteLine(staturl.pwcsUrl); } Console.ReadLine(); }
internal BrowserHistory[] GetHistory_IE() { List <BrowserHistory> history = new List <BrowserHistory>(); IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2) new UrlHistory(); IEnumSTATURL vEnumSTATURL = vUrlHistoryStg2.EnumUrls(); STATURL vSTATURL; uint vFectched; while (vEnumSTATURL.Next(1, out vSTATURL, out vFectched) == 0) { var bh = new BrowserHistory() { User = "******", Browser = "IE", Url = vSTATURL.pwcsUrl, Timestamp = FromFileTime(vSTATURL.ftLastVisited) }; history.Add(bh); } //vUrlHistoryStg2.ClearHistory();//Clear the history return(history.ToArray()); }