Delete Temporary Internet Files

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;
    DWORD  dwTrySize, dwEntrySize = 4096; // start buffer size    
    HANDLE hCacheDir = NULL;    
        switch (dwError)
            // need a bigger 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;
                    bSuccess = FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize);

                if (bSuccess)
                    dwError = ERROR_SUCCESS;    
                    dwError = GetLastError();
                    dwEntrySize = dwTrySize; // use new size returned

             // we are done
            case ERROR_NO_MORE_ITEMS:
                bDone = TRUE;
                bResult = TRUE;                

             // we have got an entry
            case ERROR_SUCCESS:                       
                // don't delete cookie entry
                if (!(lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY))                
                // get ready for next entry
                dwTrySize = dwEntrySize;
                if (FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize))
                    dwError = ERROR_SUCCESS;          
                    dwError = GetLastError();
                    dwEntrySize = dwTrySize; // use new size returned

            // unknown error
                bDone = TRUE;                

        if (bDone)
            delete [] lpCacheEntry; 
            if (hCacheDir)
    } while (!bDone);
    return bResult;


  • Solution to Delete Temporary Internet Files in IE 6

    Posted by divesh4u on 06/09/2006 07:25am

    You can do this by following steps:
    You can type simpely in header 
    #pragma comment(lib, "wininet.lib") 
    In the your Project in VC++ 6.0
    Go to Project -> Settings -> Links
    In the Object/Library Modules type: Wininet.lib
    It will definately work.
    Divesh K. Jain

    • How does it work?

      Posted by WorldNet on 10/03/2006 03:53pm

      Are you going to use a NOTEPAD to use this code? Thanks

  • This doesn't work .... :-(

    Posted by acroitoriu on 04/24/2005 04:35pm

    I 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...

    • Solution

      Posted by divesh4u on 06/09/2006 07:34am

      Look at my Topic Solution To Delete Temporary Internet Files in IE 6

    • My code is also not working

      Posted by Djain on 06/08/2006 09:02am

      I'm also using IE 6.0. it not working for me. Please provide the solution for IE 6.0.

  • how to delete cookie and temporary internet files using java

    Posted by Legacy on 02/12/2004 12:00am

    Originally posted by: sami

    how to delete cookie and temporary internet files using java
    send me mail ..

    i'm doing project

  • How to recognise the file extension of cached items in the Internet Temporary Files folder ?

    Posted by Legacy on 01/15/2004 12:00am

    Originally posted by: Brent

    HI, there

    I am making a programme that is expected to be able to fetch the pictures files in the Internet Temporary Files folder, such as .jpg and .gif etc. My thoughts is to use winInet API to recognise each cacheEntry's extension, if it is .jpg or .gif then do the further manipulation.

    The CacheEntry variable is definded as:

    In a loop, when each item is fetched by FindNextUrlCacheEntry , and then I wish to use lpCacheEntry -> lpszFileExtension to find out the extension of the cached entry. The problem is lpCacheEntry -> lpszFileExtension seems cannot contain some extention like "jpg" or "gif", (but I found no prolem with "htm" or "css" etc.)so I cannot use something like:
    if (lpCacheEntry -> lpszFileExtension is "jpg") then do....

    the date type of lpszFileExtension is LPTSTR.

    Does anyone can help me, please. Thank you

  • How To Recover The The Deleted URL Cache .......?

    Posted by Legacy on 01/12/2004 12:00am

    Originally posted by: Nilesh

    Help...How To Recover The The Deleted URL Cache .......?

    Plz Help Me.....

  • How do you do this in C#

    Posted by Legacy on 12/11/2003 12:00am

    Originally 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#?


    • How do u do this in C#

      Posted by saravanan_article on 01/30/2006 11:22pm

      this is exactly what i need to do but these things need to be do in C#. Please post the code.

  • Great Solution

    Posted by Legacy on 12/02/2003 12:00am

    Originally posted by: milind

    Greate Solution... works perfect ... thanks for code

  • good code

    Posted by Legacy on 09/17/2003 12:00am

    Originally posted by: 박진삼

    정말 좋네요
    임시파일들이 모두 지워졌습니다..
    그리고 아쉬운 점이 있다면 임의의 파일만 지울수 있었으면
    하는 소망이 있네요...^^


  • Trying to make a DLL out of this program

    Posted by Legacy on 08/29/2003 12:00am

    Originally posted by: SA

    Hello All,
    I am trying to create a DLL from this clear temp files program using Visual Studio .NET and I get a lot of errors like:
    error C2061: syntax error : identifier 'HINTERNET'
    error C2059: syntax error : ';'
    error C2061: syntax error : identifier 'DWORD'
    more than 100 errors.

    I have included the following at the start of the file:
    #pragma comment(lib, "WinInet.lib")

    Here is the command I use to create the dll:
    cl -I -LD ClearTempFile.c -Fecookie.dll

    Can someone tell me what am I doing wrong?


  • how to find ip address of user connected to internet

    Posted by Legacy on 08/19/2003 12:00am

    Originally posted by: adlubadlu

    suggest me how to find ip address of user connected to internet using visual basic 6

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 23, 2015 The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this webcast to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code reviews, build automation, and …

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date