type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses WinINet;
procedure ClearTempInternetFiles(RemCookies: boolean);
var
lpEntryInfo: PInternetCacheEntryInfo;
hCacheDir: LongWord (*Handle*);
dwEntrySize, dwLastError: LongWord;
begin
//Get size of first entry in dwEntrySize
dwEntrySize := 0;
FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize);
//Create structure that can hold entry
GetMem(lpEntryInfo, dwEntrySize);
try
//Get first cache entry and handle to retrieve next entry, output url
hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize);
if hCacheDir = 0 then
exit;
if (hCacheDir <> 0) and
((lpEntryInfo^.CacheEntryType and NORMAL_CACHE_ENTRY) = NORMAL_CACHE_ENTRY) then
begin
if ((lpEntryInfo^.CacheEntryType and COOKIE_CACHE_ENTRY) = 0) or RemCookies then
begin
if FileExists(string(lpEntryInfo^.lpszLocalFileName)) then
DeleteFile(string(lpEntryInfo^.lpszLocalFileName)); //delete file
if dwLastError = ERROR_INSUFFICIENT_BUFFER then begin
GetMem(lpEntryInfo, dwEntrySize);
try
if FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize) then begin
if ((lpEntryInfo^.CacheEntryType and NORMAL_CACHE_ENTRY) = NORMAL_CACHE_ENTRY) then
begin
if ((lpEntryInfo^.CacheEntryType and COOKIE_CACHE_ENTRY) = 0) or RemCookies then
begin
if FileExists(string(lpEntryInfo^.lpszLocalFileName)) then
DeleteFile(string(lpEntryInfo^.lpszLocalFileName)); //delete file
DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);
end;
end;
end else
exit;
finally
FreeMem(lpEntryInfo);
end;
end else
exit;
until dwLastError = ERROR_NO_MORE_ITEMS;
end;