USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  Visual Basic    (Internet)

Título da Dica:  Listando todos os cookies e arquivos temporários da internet (Temporary Internet Files)
Postada em 12/3/2004 por Josefh Hennyere         
'Insira num Form, 3 Command Buttons, 1 List Box e  1 Label
'Command1 - Lista todos os cookies e arquivos temporários
'Command2 - Apaga o arquivo selecionado
'Command3 - Apaga todos os arquivos

'Num módulo.bas

Option Explicit
Public Const ERROR_CACHE_FIND_FAIL As Long = 0
Public Const ERROR_CACHE_FIND_SUCCESS As Long = 1
Public Const ERROR_FILE_NOT_FOUND As Long = 2
Public Const ERROR_ACCESS_DENIED As Long = 5
Public Const ERROR_INSUFFICIENT_BUFFER As Long = 122
Public Const MAX_PATH As Long = 260
Public Const MAX_CACHE_ENTRY_INFO_SIZE As Long = 4096

Public Const LMEM_FIXED As Long = &H0
Public Const LMEM_ZEROINIT As Long = &H40
Public Const LPTR As Long = (LMEM_FIXED Or LMEM_ZEROINIT)

Public Const NORMAL_CACHE_ENTRY As Long = &H1
Public Const EDITED_CACHE_ENTRY As Long = &H8
Public Const TRACK_OFFLINE_CACHE_ENTRY As Long = &H10
Public Const TRACK_ONLINE_CACHE_ENTRY As Long = &H20
Public Const STICKY_CACHE_ENTRY As Long = &H40
Public Const SPARSE_CACHE_ENTRY As Long = &H10000
Public Const COOKIE_CACHE_ENTRY As Long = &H100000
Public Const URLHISTORY_CACHE_ENTRY As Long = &H200000
Public 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
Public Type FILETIME
   dwLowDateTime As Long
   dwHighDateTime As Long
End Type

Public 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

Public Declare Function FindFirstUrlCacheEntry Lib "wininet" _
   Alias "FindFirstUrlCacheEntryA" _
  (ByVal lpszUrlSearchPattern As String, _
   lpFirstCacheEntryInfo As Any, _
   lpdwFirstCacheEntryInfoBufferSize As Long) As Long

Public Declare Function FindNextUrlCacheEntry Lib "wininet" _
   Alias "FindNextUrlCacheEntryA" _
  (ByVal hEnumHandle As Long, _
   lpNextCacheEntryInfo As Any, _
   lpdwNextCacheEntryInfoBufferSize As Long) As Long

Public Declare Function FindCloseUrlCache Lib "wininet" _
   (ByVal hEnumHandle As Long) As Long

Public Declare Function DeleteUrlCacheEntry Lib "wininet" _
   Alias "DeleteUrlCacheEntryA" _
  (ByVal lpszUrlName As String) As Long
  
Public Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
   (pDest As Any, _
    pSource As Any, _
    ByVal dwLength As Long)

Public Declare Function lstrcpyA Lib "kernel32" _
  (ByVal RetVal As String, ByVal Ptr As Long) As Long
                        
Public Declare Function lstrlenA Lib "kernel32" _
  (ByVal Ptr As Any) As Long
  
Public Declare Function LocalAlloc Lib "kernel32" _
   (ByVal uFlags As Long, _
    ByVal uBytes As Long) As Long
    
Public Declare Function LocalFree Lib "kernel32" _
   (ByVal hMem As Long) As Long



'No Form

Option Explicit

Private Sub Command1_Click()
   GetCacheURLList
   Label1.Caption = List1.ListCount & " files listed."

End Sub

Private Sub Command2_Click()

   Dim cachefile As String
   cachefile = List1.List(List1.ListIndex)
   Call DeleteUrlCacheEntry(cachefile)
  
   GetCacheURLList
  
End Sub

Private Sub Command3_Click()

   Dim cachefile As String
   Dim i As Long
    
   For i = 0 To List1.ListCount - 1
  
      cachefile = List1.List(i)
      If InStr(cachefile, "Cookie") = 0 Then

         Call DeleteUrlCacheEntry(cachefile)

      End If
  
   Next
  
   GetCacheURLList
  
End Sub

Private Sub List1_Click()

   Command2.Enabled = InStr(List1.List(List1.ListIndex), "Cookie") = 0

End Sub

Public Sub GetCacheURLList()
    
   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
  
   List1.Clear
   dwBuffer = 0

   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 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)
                  List1.AddItem cachefile

               End If
              
               Call LocalFree(pntrICE)
              
               dwBuffer = 0
               Call FindNextUrlCacheEntry(hFile, ByVal 0, dwBuffer)
              
               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 Function GetStrFromPtrA(ByVal lpszA As Long) As String

   GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)
   Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)
  
End Function


'Josefh Hennyere
 


CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página