DelphiFAQ Home Search:

Programmatically clear Internet Explorer's cache

 

comments4 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.

Question:

I need a tool to empty IE's cache on a regular basis. How can I quickly write that myself?

Answer:

You can use a quick and dirty approach if you need to delete the cache only on one specific computer. In this case write a batch file that contains the following statements (replace 'administrator' with your user name):

del "c:\Temp\*.*" /ARSAH /s /q
del "c:\documents and settings\administrator\Recent\*.*" /s /q /a
del "c:\documents and settings\administrator\History\*.*" /s /q /a
del "c:\documents and settings\administrator\Temporary Internet Files\*.*" /s /q /a


If you want a more universal tool then look at the following Delphi code. You can also download the compiled executable here: Del_IE_Cache.exe (8 kB)

program Delete_IE_Cache;

uses
  WinInet;

{sc-----------------------------------------------------------------------
  Name:       DeleteIECache
  Parameters: -
-----------------------------------------------------------------------sc}
procedure DeleteIECache;
var
  lpEntryInfo: PInternetCacheEntryInfo;
  hCacheDir: LongWord;
  dwEntrySize: LongWord;
begin { DeleteIECache }
  dwEntrySize := 0;

  FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize);

  GetMem(lpEntryInfo, dwEntrySize);

  if dwEntrySize>0 then
    lpEntryInfo^.dwStructSize := dwEntrySize;

  hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize);

  if hCacheDir<>0 then
  begin
    repeat
      DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);
      FreeMem(lpEntryInfo, dwEntrySize);
      dwEntrySize := 0;
      FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize);
      GetMem(lpEntryInfo, dwEntrySize);
      if dwEntrySize>0 then
        lpEntryInfo^.dwStructSize := dwEntrySize;
    until not FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize)
  end; { hCacheDir<>0 }
  FreeMem(lpEntryInfo, dwEntrySize);

  FindCloseUrlCache(hCacheDir)
end; { DeleteIECache }


begin
  DeleteIECache
end.

Comments:

2006-07-10, 18:35:11
[hidden] from Australia  
rating
The above Delphi code when executed causes ebay and various other on-line subscription services to forget who I am. Seems to me it must be doing more than just clearing the cache. I think it's wiping out my cookies which is exactly what I didn't want to happen.

2. 'My' XP system does not have the subdirectories mentioned in the above batch file.
2007-01-29, 05:31:09
anonymous from India  
I need to delete files from the internet explorer each time i call an action to view my latest graph charts that i am creating at runtime in HTL page.
Please guide me how can i delete the interent files programmaticaaly.
2008-04-16, 07:01:48
anonymous from Nigeria  
I'm hosting an online application that displays videos. I need the users browser to pick up the latest videos.
2009-07-09, 11:49:51
anonymous from Switzerland  
rating
To prevent the deletion of cookies too, insert the following if-statement:

repeat
if lpEntryInfo^.CacheEntryType and COOKIE_CACHE_ENTRY = COOKIE_CACHE_ENTRY then
DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);

The constant COOKIE_CACHE_ENTRY should have the value $00100000.

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: