Deleting the Internet Explorer Cache programmatically

12 Jan 2004 12:05

Here’s some C source code that does it.

char buffer[4096];
DWORD cb = 4096;

INTERNET_CACHE_ENTRY_INFO *p = (INTERNET_CACHE_ENTRY_INFO *)buffer;
HANDLE h = FindFirstUrlCacheEntry(NULL, p, &cb);
while (h)
{
    // Do something with it...
    printf("Deleting: %s...", p->lpszSourceUrlName);
    if (!DeleteUrlCacheEntry(p->lpszSourceUrlName))
    {
        printf("failed, 0x%x\n", GetLastError());
    }
    else
        printf("ok\n");

    cb = 4096;
    if (!FindNextUrlCacheEntry(h, (INTERNET_CACHE_ENTRY_INFO *)buffer, &cb))
        break;
}