How to clear browsing history using WebBrowser control in C#

99封情书 提交于 2019-11-30 10:11:19

问题


I want to clear the browsing history of a WebBrowser control in C# after the WebBrowser completes its browsing.

This is my code:

try
{
    foreach (string sr in File.ReadAllLines("link.txt"))
    {
        webBrowser1.Navigate(sr);
        webBrowser1.ScriptErrorsSuppressed = true;
    }
    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
    {
        Application.DoEvents();
    }                               
}
catch(Exception)
{
    MessageBox.Show("Internet Connection not found","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
    this.Close();
}

回答1:


Temporary Internet Files

System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 8")

Cookies()

System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 2")

History()

System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 1")

Form(Data)

System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 16")

Passwords

System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 32")

Delete(All)

System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 255")

Delete All – Also delete files and settings stored by add-ons

System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 4351")



回答2:


Actually, there are two types of history. One is "Visited" pages list, and the other is the actual history you see in IE's history user interface.

You will get 3 types of cache, on starting with "Cookie: ", another starting with "Visited: " - which just represents the visited sites list (it isn't the history, don't confuse the two), and the last type just comes in the form of a url begining with http:// or https://. Once you are looping through, you can pick and choose which ones you want to delete.

If you want to remove the visited pages list, you need to use DeleteUrlCacheEntry to delete each item. By looping through using FindFirst/NextUrlCacheEntry API's you can get access to the time and date these items were created, and therefore only delete the items created after your browser session started and before it was finished.

For FindFirst/NextUrlCacheEntry and DeleteUrlCacheEntry information, there are pre-written codes online that you can use, and then it will be easy for you to create a filter to decide which items you want deleted when you are looping through these cache entries.

Let me know if I can be of further assistance.



来源:https://stackoverflow.com/questions/11931795/how-to-clear-browsing-history-using-webbrowser-control-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!