COMO APAGAR ARQUIVOS TEMPORARIOS?

MLALEX 09/10/2013 10:47:59
#429735
Gente SOCORRO!!! Como apagar os arquivos em C:\Users\Usuario\AppData\Local\Microsoft\Windows\Temporary Internet Files???

Já pesquisei na net toda. Achei o código abaixo mas dá erro na função: DeleteUrlCacheEntry GetStrFromPtr(ICEI.lpszSourceUrlName)

Código:
Citação:

[ô] Constants for API
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_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 Const CLSID_CUrlHistory = [Ô]{3C374A40-BAE4-11CF-BF7D-00AA006946EE}[Ô]
Private Const CLSID_IUrlHistoryStg2 = [Ô]{AFA0DC11-C313-11D0-831A-00C04FD5AE38}[Ô]
Private Const IUrlHistoryStg2_Release As Long = 8&
Private Const IUrlHistoryStg2_ClearHistory As Long = 36&
Private Const CLSCTX_INPROC_SERVER As Long = 1&
Private Const CC_STDCALL As Long = 4&
Private Const S_OK As Long = 0&

Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type

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

[ô] API declarations for clearing browser cache
Private Declare Function CLSIDFromString Lib [Ô]ole32[Ô] (ByVal lpszGuid As Long, pGuid As Any) As Long
Private Declare Function CoCreateInstance Lib [Ô]ole32[Ô] (rclsid As Any, ByVal pUnkOuter As Long, ByVal dwClsContext As Long, riid As Any, pvarResult As Long) As Long
Private Declare Sub CopyMemory Lib [Ô]kernel32[Ô] Alias [Ô]RtlMoveMemory[Ô] (pDest As Any, pSource As Any, ByVal dwLength As Long)
Private Declare Function DeleteUrlCacheEntry Lib [Ô]wininet.dll[Ô] Alias [Ô]DeleteUrlCacheEntryA[Ô] (ByVal lpszUrlName As String) As Long
Private Declare Function DispCallFunc Lib [Ô]oleaut32[Ô] (ByVal pvarResult As Long, ByVal oVft As Long, ByVal cc As Long, ByVal vtReturn As VbVarType, ByVal nParams As Long, pVarTypes As Long, pVarArgs As Long, pvarResult As Variant) As Long
Private Declare Function FindCloseUrlCache Lib [Ô]wininet[Ô] (ByVal hEnumHandle As Long) As Long
Private Declare Function FindFirstUrlCacheEntry Lib [Ô]wininet.dll[Ô] Alias [Ô]FindFirstUrlCacheEntryA[Ô] (ByVal lpszUrlSearchPattern As String, ByRef lpFirstCacheEntryInfo As Any, ByRef lpdwFirstCacheEntryInfoBufferSize As Long) As Long
Private Declare Function FindNextUrlCacheEntry Lib [Ô]wininet.dll[Ô] Alias [Ô]FindNextUrlCacheEntryA[Ô] (ByVal hEnumHandle As Long, ByRef lpNextCacheEntryInfo As Any, ByRef lpdwNextCacheEntryInfoBufferSize As Long) 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
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 GetStrFromPtr() As Variant

Public Sub ClearCache()
Dim ICEI As INTERNET_CACHE_ENTRY_INFO
Dim hFile As Long
Dim cachefile As String
Dim nCount As Long
Dim dwBuffer As Long
Dim pntrICE As Long
Const COOKIE_CACHE_ENTRY As Long = &H100000
Dim strCookie As String
Dim blnProtected As Boolean

dwBuffer = 0
[ô]Get the required buffer size
hFile = FindFirstUrlCacheEntry(vbNullString, ByVal 0, dwBuffer)
[ô]both conditions should be met by the first call
If (hFile = ERROR_CACHE_FIND_FAIL) And _
(Err.LastDllError = ERROR_INSUFFICIENT_BUFFER) Then

[ô]The INTERNET_CACHE_ENTRY_INFO data type is a
[ô]variable-length type. It is necessary to allocate
[ô]memory for the result of the call and pass the
[ô]pointer to this memory location to the API.
pntrICE = LocalAlloc(LMEM_FIXED, dwBuffer)
[ô]allocation successful
If pntrICE Then
[ô]set a Long pointer to the memory location
CopyMemory ByVal pntrICE, dwBuffer, 4
[ô]and call the first find API again passing the
[ô]pointer to the allocated memory
hFile = FindFirstUrlCacheEntry(vbNullString, ByVal pntrICE, dwBuffer)
[ô]hfile should = 1 (success)
If hFile <> ERROR_CACHE_FIND_FAIL Then
[ô]now just loop through the cache
Do
[ô]the pointer has been filled, so move the
[ô]data back into a ICEI structure
CopyMemory ICEI, ByVal pntrICE, Len(ICEI)

[ô]CacheEntryType is a long representing the type of
[ô]entry returned.
blnProtected = False
If (ICEI.CacheEntryType And COOKIE_CACHE_ENTRY) Then
strCookie = GetStrFromPtr(ICEI.lpszSourceUrlName)
strCookie = Mid$(strCookie, InStr(strCookie, [Ô]@[Ô]) + 1)
End If
DeleteUrlCacheEntry GetStrFromPtr(ICEI.lpszSourceUrlName)

[ô]free the pointer and memory associated
[ô]with the last-retrieved file
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
Loop While FindNextUrlCacheEntry(hFile, ByVal pntrICE, dwBuffer)
End If
End If
End If
Call LocalFree(pntrICE)
Call FindCloseUrlCache(hFile)
End Sub

Public Sub ClearHistory()
Dim objClsid As GUID
Dim idClsid As GUID
Dim pvarResult As Long
Dim ret As Long

Call CLSIDFromString(StrPtr(CLSID_CUrlHistory), objClsid)
Call CLSIDFromString(StrPtr(CLSID_IUrlHistoryStg2), idClsid)
If CoCreateInstance(objClsid, 0&, CLSCTX_INPROC_SERVER, idClsid, pvarResult) = S_OK Then
If DispCallFunc(pvarResult, IUrlHistoryStg2_ClearHistory, CC_STDCALL, vbLong, 0&, 0&, 0&, ret) = S_OK Then
DispCallFunc pvarResult, IUrlHistoryStg2_Release, CC_STDCALL, vbLong, 0&, 0&, 0&, ret
End If
End If
End Sub



SOCORRO!!! PELO AMOR DE DEUS!!!!
MARCELO.TREZE 09/10/2013 11:34:47
#429741
Resposta escolhida
FILMAN 09/10/2013 11:36:22
#429742
Sugiro que mude o título do seu post, pois esta infligindo as regras do forum!
MLALEX 09/10/2013 12:46:50
#429747
Olá Filman!! Peço desculpas, mas não sei onde estou indo contra as regras do fórum. Tirei a palavra SOCORRO. Seria isso??

Olá Marcelo!! Tentei os dois programas mas nenhum apagou os arquivos. Parece que eles não agem em C:\Users\Usuario\AppData\Local\Microsoft\Windows\Temporary Internet Files. Tentei forçar esse endereço, mas também não deu certo.

O problema é quando faço download com o mesmo nome de um mesmo endereço. Apesar de ter o mesmo nome, o conteúdo desse arquivo é diferente, mas ele simplesmente não é atualizado. Quanto apago os arquivos temporários no endereço acima usando o CCleaner, aí atualiza... se houver outra forma de resolver o problema??
MLALEX 09/10/2013 13:22:28
#429751
Marcelo, parece que os programas são para uso em Win XP e eu uso o Seven....
FILMAN 09/10/2013 15:01:01
#429759
Olá, MLALEX não leve a mal é que estamos tentando melhorar a qualidade do forum e era isso mesmo a palavra SOCORRO é imprópria para utilização nesse sentido


Mas quando ao uso dos exemplo do MARCELO

tente desabilitar o Controle de Usuário (UAC) pode ser que resolva, não baixei os exemplos, mas é uma alternativa.
MLALEX 09/10/2013 15:58:24
#429780
Filman, já estou com esse Controle desabilitado.

No exemplo:
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=63785&lngWId=1&txtForceRefresh=109201310364253554
o caminho original é: flp = Environ$([Ô]HOMEDRIVE[Ô]) & Environ$([Ô]HOMEPATH[Ô]) & [Ô]\Cookies[Ô]
troquei por flp = [Ô]C:\Users\Quasar\AppData\Local\Microsoft\Windows\Temporary Internet Files[Ô]
O programa fala que apagou os arquivos mas eles continuam lá.

Tá difícil o negócio...
MLALEX 09/10/2013 19:10:16
#429799
GENTE!!! Achei uma solução mais simples:

- Apagar todos os caches

- Zerar o armazenamento de caches

SIMPLES ASSIM... mas perdi dois dias pesquisando código para apagar esses tais caches...


VALEU TODO MUNDO!!
Tópico encerrado , respostas não são mais permitidas