Jump to content

Clearing Temporary Internet Files


Recommended Posts

I found a C++ version of Clearing the Temporary Internet files.

Is there anybody who can convert this program to AutoIT?

Maybe it can be implemented in AutoIT in a next version....

The version below is shown without removing cookies, but it must be WITH removing cookies. I really don't know anything about C++, but it has to be something with the "// don't delete cookie entry".

#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;
}
Link to comment
Share on other sites

wow, I'm glad I don't use C++ (learning C).

See the other post you created, one of the other lines of code has this one too.

8)

<{POST_SNAPBACK}>

Errr, if you are learning C, then why are you glad you don't use C++? If the operator new/delete lines are replaced with malloc()/free(), that should be perfectly valid C code. So your comment makes no sense.
Link to comment
Share on other sites

valik, don't be so mean to him.

i like C++ better, because there allot easyer tutorials for it.,

its no legal reason in ur opinion, but who cares :)

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

valik, don't be so mean to him.

i like C++ better, because there allot easyer tutorials for it.,

its no legal reason in ur opinion, but who cares :)

<{POST_SNAPBACK}>

Being mean? How was I being mean? The person made a comment that they were glad they weren't learning C++, but were learning C. The only fathomable reason I can harvest from the thread itself is I see what could be viewed as "complex" code. With that being the only reason I can see from the information present, the next logical step is to assume the person is making the comment because they assume the code is doing something specific to C++ that would render the code different or potentially easier in C. Since that is in fact not the case, I felt somebody needed to point out that with a couple minor changes (which makes the code more complex), this code would be perfectly valid and normal C code.

So, in the event my assumptions are correct, the comment by the poster is based on their false assumptions about a language which they don't know enough about to make such comments. Such comments and comparisons should be avoided because people like me will call them out on it for being quite wrong. In the event that my assumption is incorrect, then I fail to see the relevance of the comment at all as pertaining to this thread.

I have no problem with people having an opinion on preferring one language to another language. I do have a problem when they base their opinions on fictitious facts, incorrect assumptions, or ignorance about the language they are stating they prefer their language over. If people are going to state their opinions on why they prefer a language, then they damn well better back it up with real information or be honest about why and not make up crap or base their opinion on false facts or I will call them on it.

Link to comment
Share on other sites

:| that hurts ur ego :)

thanks for the BIG explaining :D

ps. make a program that makes these awnsers, or flames :D

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

What I meant is that with all those lines of code he had, I did it in one with AU3.

I'm taking a C++ class next year.

<{POST_SNAPBACK}>

Whow, I really wish it was that easy!!!

Of coarse I allready tried this one line, but that really doesn't work.

It seems that the code I mentioned DOES work, but I need someone to translate it to an AutoIt version.

So If anyone could come up with this translation, that would be very nice!

I've been looking all over the internet to find a source to clean all the damned Cache of the Internet explorer, but I can't find it anywere. There are lots of small compiled programs, but they all need to be installed first and they all have a graphical UI. If only one of them could be used from the command prompt, I could use the RUNWAIT funktion to start it. But of course, I'd prefer to use an AUTOIT version!

Please Put this functionality in AUTOIT .. :)

Link to comment
Share on other sites

I think the best way to Clear the Internet Explorer (History, Cookies and On and Offline-Files) is by clicking the buttons in the Internet Options Page, but the only way by clicking this automaticly is to write a script that opens the windows and click the buttons. I already made such a script, but I wonder if there isn't a more direct way to do this?

Is there a way to push a button directly by using Control's (or maybe DllCall?) without opening the corresponding Windows?

Link to comment
Share on other sites

  • 2 years later...

VB:

Option Explicit

Private Const ERROR_CACHE_FIND_FAIL As Long = 0

Private Const ERROR_CACHE_FIND_SUCCESS As Long = 1

Private Const ERROR_FILE_NOT_FOUND As Long = 2

Private Const ERROR_ACCESS_DENIED As Long = 5

Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122

Private Const MAX_PATH As Long = 260

Private Const MAX_CACHE_ENTRY_INFO_SIZE As Long = 4096

Private Const LMEM_FIXED As Long = &H0

Private Const LMEM_ZEROINIT As Long = &H40

Private Const LPTR As Long = (LMEM_FIXED Or LMEM_ZEROINIT)

Private Const NORMAL_CACHE_ENTRY As Long = &H1

Private Const EDITED_CACHE_ENTRY As Long = &H8

Private Const TRACK_OFFLINE_CACHE_ENTRY As Long = &H10

Private Const TRACK_ONLINE_CACHE_ENTRY As Long = &H20

Private Const STICKY_CACHE_ENTRY As Long = &H40

Private Const SPARSE_CACHE_ENTRY As Long = &H10000

Private Const COOKIE_CACHE_ENTRY As Long = &H100000

Private Const URLHISTORY_CACHE_ENTRY As Long = &H200000

Private Const URLCACHE_FIND_DEFAULT_FILTER As Long = NORMAL_CACHE_ENTRY Or _

COOKIE_CACHE_ENTRY Or _

URLHISTORY_CACHE_ENTRY Or _

TRACK_OFFLINE_CACHE_ENTRY Or _

TRACK_ONLINE_CACHE_ENTRY Or _

STICKY_CACHE_ENTRY

Private Type FILETIME

dwLowDateTime As Long

dwHighDateTime As Long

End Type

Private Type INTERNET_CACHE_ENTRY_INFO

dwStructSize As Long

lpszSourceUrlName As Long

lpszLocalFileName As Long

CacheEntryType As Long

dwUseCount As Long

dwHitRate As Long

dwSizeLow As Long

dwSizeHigh As Long

LastModifiedTime As FILETIME

ExpireTime As FILETIME

LastAccessTime As FILETIME

LastSyncTime As FILETIME

lpHeaderInfo As Long

dwHeaderInfoSize As Long

lpszFileExtension As Long

dwExemptDelta As Long

End Type

Private Declare Function FindFirstUrlCacheEntry Lib "wininet" _

Alias "FindFirstUrlCacheEntryA" _

(ByVal lpszUrlSearchPattern As String, _

lpFirstCacheEntryInfo As Any, _

lpdwFirstCacheEntryInfoBufferSize As Long) As Long

Private Declare Function FindNextUrlCacheEntry Lib "wininet" _

Alias "FindNextUrlCacheEntryA" _

(ByVal hEnumHandle As Long, _

lpNextCacheEntryInfo As Any, _

lpdwNextCacheEntryInfoBufferSize As Long) As Long

Private Declare Function FindCloseUrlCache Lib "wininet" _

(ByVal hEnumHandle As Long) As Long

Private Declare Function DeleteUrlCacheEntry Lib "wininet" _

Alias "DeleteUrlCacheEntryA" _

(ByVal lpszUrlName As String) As Long

Private Declare Sub CopyMemory Lib "kernel32" _

Alias "RtlMoveMemory" _

(pDest As Any, _

pSource As Any, _

ByVal dwLength As Long)

Private Declare Function lstrcpyA Lib "kernel32" _

(ByVal RetVal As String, ByVal Ptr As Long) As Long

Private Declare Function lstrlenA Lib "kernel32" _

(ByVal Ptr As Any) As Long

Private Declare Function LocalAlloc Lib "kernel32" _

(ByVal uFlags As Long, _

ByVal uBytes As Long) As Long

Private Declare Function LocalFree Lib "kernel32" _

(ByVal hMem As Long) As Long

Public Sub DeleteCacheURLList()

Dim icei As INTERNET_CACHE_ENTRY_INFO

Dim hFile As Long

Dim cachefile As String

Dim posUrl As Long

Dim posEnd As Long

Dim dwBuffer As Long

Dim pntrICE As Long

hFile = FindFirstUrlCacheEntry(0&, ByVal 0, dwBuffer)

If (hFile = ERROR_CACHE_FIND_FAIL) And _

(Err.LastDllError = ERROR_INSUFFICIENT_BUFFER) Then

pntrICE = LocalAlloc(LMEM_FIXED, dwBuffer)

If pntrICE <> 0 Then

CopyMemory ByVal pntrICE, dwBuffer, 4

hFile = FindFirstUrlCacheEntry(vbNullString, _

ByVal pntrICE, _

dwBuffer)

If hFile <> ERROR_CACHE_FIND_FAIL Then

Do

CopyMemory icei, ByVal pntrICE, Len(icei)

If (icei.CacheEntryType And _

NORMAL_CACHE_ENTRY) = NORMAL_CACHE_ENTRY Then

cachefile = GetStrFromPtrA(icei.lpszSourceUrlName)

Call DeleteUrlCacheEntry(cachefile)

End If

Call LocalFree(pntrICE)

dwBuffer = 0

Call FindNextUrlCacheEntry(hFile, ByVal 0, dwBuffer)

'allocate and assign the memory to the pointer

pntrICE = LocalAlloc(LMEM_FIXED, dwBuffer)

CopyMemory ByVal pntrICE, dwBuffer, 4

DoEvents

Loop While FindNextUrlCacheEntry(hFile, ByVal pntrICE, dwBuffer)

End If 'hFile

End If 'pntrICE

End If 'hFile

Call LocalFree(pntrICE)

Call FindCloseUrlCache(hFile)

End Sub

Private Function GetStrFromPtrA(ByVal lpszA As Long) As String

GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)

Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)

End Function

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...