以编程方式清除IE缓存与InetCpl.cpl,ClearMyTracksByProcess

时间:2011-03-11 14:49:53

标签: wininet

我有一个托管webbrowser控件的应用程序,它使用我的microsoft提供的代码示例清除缓存(定期): http://support.microsoft.com/kb/262110

但是我注意到,经过一段时间后,缓存被破坏或无法正常工作(应该超出缓存的请求 - 一遍又一遍地调用。

当我运行以下命令时,应用程序开始正常运行。 system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8')

两者是否相同,或者代码缺少什么?

1 个答案:

答案 0 :(得分:5)

在IE9中,我运行了InetCpl.cpl,ClearMyTracksByProcess 8并且它没有删除任何东西,所以看起来MS再次移动了目标帖子。

下面显示的是我选择的一些非常好的代码,应该可以在IE7中运行,但是如果你想要在win7和IE8 / 9上执行该技巧的代码,那么请点击我的名字

public static class ClearMyTracks {
 /*
  * To clear IE temporary Internet files – ClearMyTracksByProcess 8
  * To clear IE browsing cookies – ClearMyTracksByProcess 2
  * To clear IE browsing history – ClearMyTracksByProcess 193 (ALSO deletes add on history)
  * To clear IE form data- ClearMyTracksByProcess 16
  * To clear IE remembered passwords for filling web login forms-ClearMyTracksByProcess 32
  * To clear or delete all IE browsing history – all of above!- ClearMyTracksByProcess 255
  * To clear IE Tracking- ClearMyTracksByProcess 2048
  * Preserve Favourites use 8192
  * To clear IE Downloaded Files- ClearMyTracksByProcess 16384 
  * http://www.howtogeek.com/howto/windows/clear-ie7-browsing-history-from-the-command-line/
  */

public enum ClearFlags {
  DeleteCookies = 2, 
  DeleteHistoryFiles = 8, 
  DeleteFormData = 16, 
  DeletePasswords = 32,
  DeleteHistory = 193, 
  DeleteALLHistory = 255, 
  DeleteTrackingInfo = 2048,
  PreserveFavourites = 8192, 
  DeleteDownloadHistory = 16384, 
  DeleteEverything = 22783
 };

public static void IEClearHistory(bool PreserveFavs, bool TempFiles, bool Cookies, bool History, bool form, bool passwords, bool downloads) {
  uint mask = 0;

  if (PreserveFavs)
    mask |= (uint)ClearFlags.PreserveFavourites;

  if (TempFiles)
    mask |= (uint)ClearFlags.DeleteHistoryFiles;

  if (Cookies)
    mask |= (uint)ClearFlags.DeleteCookies;

  if (History)
    mask |= (uint)ClearFlags.DeleteHistory;

  if (form)
    mask |= (uint)ClearFlags.DeleteFormData;

  if (passwords)
    mask |= (uint)ClearFlags.DeletePasswords;

  if (downloads)
    mask |= (uint)ClearFlags.DeleteDownloadHistory;

  if (mask != 0)
    System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess " + mask.ToString());
}