Delete Temporary Internet Files
Posted
by Peter Sun
on December 16th, 1999
In IE5, you can delete Temporary Internet Files in "Internet Options" property sheet. Do you ever wonder how to delete Temporary Internet Files in your application? Here is how it can be done by using WinInet APIs: FindFirstUrlCacheEntry, FindNextUrlCacheEntry, DeleteUrlCacheEntry, and FindCloseUrlCache.
It is not documented, but I have tested it and it works, with VC++ 6.0 on Win98/NT.
#include <wininet.h>
//
// Delete all files in the Temporary Internet Files folder
//
// Note that you can specify what NOT to delete by testing entry type
// In code below, cookie entries are not deleted
// [see if (!(lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY))]
//
BOOL DelTempFiles()
{
BOOL bResult = FALSE;
BOOL bDone = FALSE;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;
DWORD dwTrySize, dwEntrySize = 4096; // start buffer size
HANDLE hCacheDir = NULL;
DWORD dwError = ERROR_INSUFFICIENT_BUFFER;
do
{
switch (dwError)
{
// need a bigger buffer
case ERROR_INSUFFICIENT_BUFFER:
delete [] lpCacheEntry;
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];
lpCacheEntry->dwStructSize = dwEntrySize;
dwTrySize = dwEntrySize;
BOOL bSuccess;
if (hCacheDir == NULL)
bSuccess = (hCacheDir
= FindFirstUrlCacheEntry(NULL, lpCacheEntry,
&dwTrySize)) != NULL;
else
bSuccess = FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize);
if (bSuccess)
dwError = ERROR_SUCCESS;
else
{
dwError = GetLastError();
dwEntrySize = dwTrySize; // use new size returned
}
break;
// we are done
case ERROR_NO_MORE_ITEMS:
bDone = TRUE;
bResult = TRUE;
break;
// we have got an entry
case ERROR_SUCCESS:
// don't delete cookie entry
if (!(lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY))
DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);
// get ready for next entry
dwTrySize = dwEntrySize;
if (FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize))
dwError = ERROR_SUCCESS;
else
{
dwError = GetLastError();
dwEntrySize = dwTrySize; // use new size returned
}
break;
// unknown error
default:
bDone = TRUE;
break;
}
if (bDone)
{
delete [] lpCacheEntry;
if (hCacheDir)
FindCloseUrlCache(hCacheDir);
}
} while (!bDone);
return bResult;
}

Comments
Solution to Delete Temporary Internet Files in IE 6
Posted by divesh4u on 06/09/2006 07:25am-
ReplyHow does it work?
Posted by WorldNet on 10/03/2006 03:53pmAre you going to use a NOTEPAD to use this code? Thanks
ReplyThis doesn't work .... :-(
Posted by acroitoriu on 04/24/2005 04:35pmI tried to use your code in order to read the content of a dynamic web page (written in PHP), which always has a different content. I used your Clear Histoy code and it works, but this function doesn't work... I get the following erros: --------------------Configuration: HS_VC - Win32 Debug-------------------- Compiling... HS_VCDlg.cpp Linking... HS_VCDlg.obj : error LNK2001: unresolved external symbol __imp__FindCloseUrlCache@4 HS_VCDlg.obj : error LNK2001: unresolved external symbol __imp__DeleteUrlCacheEntry@4 HS_VCDlg.obj : error LNK2001: unresolved external symbol __imp__FindNextUrlCacheEntryA@12 HS_VCDlg.obj : error LNK2001: unresolved external symbol __imp__FindFirstUrlCacheEntryA@12 Debug/HS_VC.exe : fatal error LNK1120: 4 unresolved externals Error executing link.exe. HS_VC.exe - 5 error(s), 0 warning(s) ---------------------------------------- I'm using IE 6.0 ... under Windows XP with VC++ 6.0. This code is only for IE5??? Why it doesn't work for me ??? It's really strange...
-
-
ReplySolution
Posted by divesh4u on 06/09/2006 07:34amLook at my Topic Solution To Delete Temporary Internet Files in IE 6
ReplyMy code is also not working
Posted by Djain on 06/08/2006 09:02amI'm also using IE 6.0. it not working for me. Please provide the solution for IE 6.0.
Replyhow to delete cookie and temporary internet files using java
Posted by Legacy on 02/12/2004 12:00amOriginally posted by: sami
ReplyHow to recognise the file extension of cached items in the Internet Temporary Files folder ?
Posted by Legacy on 01/15/2004 12:00amOriginally posted by: Brent
Reply
How To Recover The The Deleted URL Cache .......?
Posted by Legacy on 01/12/2004 12:00amOriginally posted by: Nilesh
Help...How To Recover The The Deleted URL Cache .......?
Plz Help Me.....
ReplyHow do you do this in C#
Posted by Legacy on 12/11/2003 12:00amOriginally posted by: Ray Johnson
This is exactly what I need to do. But I need to do it as part of a larger C# app. I've been trying to set up the DLLImport stuff to call the wininet dll from C#. Works for some of the simplier calls in winint - like InternetGetConnectedState.
Where I'm stumped is how to declare the functions and structures for calls to FindFirstUrlCacheEntry and such. The memory allocation and such makes this not nearly as straight forward.
Has anyone done this for C#?
Ray
-
ReplyHow do u do this in C#
Posted by saravanan_article on 01/30/2006 11:22pmthis is exactly what i need to do but these things need to be do in C#. Please post the code.
ReplyGreat Solution
Posted by Legacy on 12/02/2003 12:00amOriginally posted by: milind
Greate Solution... works perfect ... thanks for code
Reply...
good code
Posted by Legacy on 09/17/2003 12:00amOriginally posted by: 박진삼
정말 좋네요
임시파일들이 모두 지워졌습니다..
그리고 아쉬운 점이 있다면 임의의 파일만 지울수 있었으면
하는 소망이 있네요...^^
Bye...
ReplyTrying to make a DLL out of this program
Posted by Legacy on 08/29/2003 12:00amOriginally posted by: SA
Replyhow to find ip address of user connected to internet
Posted by Legacy on 08/19/2003 12:00amOriginally posted by: adlubadlu
suggest me how to find ip address of user connected to internet using visual basic 6
ReplyLoading, Please Wait ...