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

  • Rocket Mobile® for IBM i is an enterprise mobile application development and deployment platform for customers who rely on the IBM i system. Rocket Mobile for IBM i enables customers to leave proven applications in-place and rapidly repurpose them into new managed and secure mobile applications. Fast, easy creation of mobile, web, and hybrid mobile applications that deploy to any iOS, Android, or Windows mobile phone or tablet Built-in integration for seamless repurposing of existing IBM i applications …

  • Complex hybrid environments can make it difficult to track interdependencies, increasing the risk of disrupting critical business services. In this white paper by EMA, you'll learn how application discovery and dependency mapping can help you: Meet granular targets for availability, cost, and time-to-revenue for cloud services. Accelerate mean time to repair (MTTR) while communicating better with stakeholders. Manage even the most complex hybrid environments more efficiently and effectively Understand the …

Most Popular Programming Stories

More for Developers

RSS Feeds

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