如何获取(清除)IE缓存地址信息

一、主要用到以下几个API:
1、FindFirstUrlCacheEntry
2、FindNextUrlCacheEntry
3、FindCloseUrlCache 
下面的内容摘自MSDN:
-------------------------------------------------------------------------------------------------------------------------------------------------------
 

FindFirstUrlCacheEntry
Begins the enumeration of the Internet cache.
HANDLE FindFirstUrlCacheEntry( LPCTSTR lpszUrlSearchPattern, LPINTERNET_CACHE_ENTRY_INFO lpFirstCacheEntryInfo, LPDWORD lpcbCacheEntryInfo );
Parameters
lpszUrlSearchPattern
[in] A pointer to a string that contains the source name pattern to search for. This parameter can only be set to "cookie:", "visited:", or NULL. Set this parameter to "cookie:" to enumerate the cookies or "visited:" to enumerate the URL History entries in the cache. If this parameter is NULL, FindFirstUrlCacheEntry returns all content entries in the cache.
lpFirstCacheEntryInfo
[out] Pointer to an INTERNET_CACHE_ENTRY_INFO structure.
lpcbCacheEntryInfo
[in, out] Pointer to a variable that specifies the size of the lpFirstCacheEntryInfo buffer, in TCHARs. When the function returns, the variable contains the number of TCHARs copied to the buffer, or the required size needed to retrieve the cache entry, in TCHARs.
Return Value
Returns a handle that the application can use in the FindNextUrlCacheEntry function to retrieve subsequent entries in the cache. If the function fails, the return value is NULL. To get extended error information, call GetLastError.
ERROR_INSUFFICIENT_BUFFER indicates that the size of lpFirstCacheEntryInfo as specified by lpdwFirstCacheEntryInfoBufferSize is not sufficient to contain all the information. The value returned in lpdwFirstCacheEntryInfoBufferSize indicates the buffer size necessary to contain all the information.
Remarks
FindFirstUrlCacheEntry and FindNextUrlCacheEntry return variable size information. If ERROR_INSUFFICIENT_BUFFER is returned, the application should allocate a buffer of the size specified by lpdwFirstCacheEntryInfoBufferSize. For more information, see Using Buffers.
Requirements

Client
Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.
Server
Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
Version
Requires Internet Explorer 3.0 or later.
Header
Declared in Wininet.h.
Library
Use Wininet.lib.
DLL
Requires Wininet.dll.
Unicode
Implemented as FindFirstUrlCacheEntryW (Unicode) and FindFirstUrlCacheEntryA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.

 ---------------------------------------------------------------------------------------------------------------------------------------------------
 
FindNextUrlCacheEntry
Retrieves the next entry in the Internet cache.
BOOLAPI FindNextUrlCacheEntry( HANDLE hEnumHandle, LPINTERNET_CACHE_ENTRY_INFO lpNextCacheEntryInfo, LPDWORD lpcbCacheEntryInfo );
Parameters
hEnumHandle
[in] Handle to the enumeration obtained from a previous call to FindFirstUrlCacheEntry.
lpNextCacheEntryInfo
[out] Pointer to an INTERNET_CACHE_ENTRY_INFO structure that receives information about the cache entry.
lpcbCacheEntryInfo
[in, out] Pointer to a variable that specifies the size of the lpNextCacheEntryInfo buffer, in TCHARs. When the function returns, the variable contains the number of TCHARs copied to the buffer, or the size of the buffer required to retrieve the cache entry, in bytes.
Return Value
Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. Possible error values include the following.
Return code
Description
ERROR_INSUFFICIENT_BUFFER
The size of lpNextCacheEntryInfo as specified by lpdwNextCacheEntryInfoBufferSize is not sufficient to contain all the information. The value returned in lpdwNextCacheEntryInfoBufferSize indicates the buffer size necessary to contain all the information.
ERROR_NO_MORE_ITEMS
The enumeration completed.
Remarks
FindNextUrlCacheEntry is called recursively until the last item in the cache is returned. The handle returned from FindFirstUrlCacheEntry is used in all subsequent calls to FindNextUrlCacheEntry.
Requirements
Client
Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.
Server
Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
Version
Requires Internet Explorer 3.0 or later.
Header
Declared in Wininet.h.
Library
Use Wininet.lib.
DLL
Requires Wininet.dll.
Unicode
Implemented as FindNextUrlCacheEntryW (Unicode) and FindNextUrlCacheEntryA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
---------------------------------------------------------------------------------------------------------------------------------------------------

FindCloseUrlCache

This function closes the specified cache enumeration handle.

BOOL FindCloseUrlCache( HANDLE hEnumHandle );

Parameters

hEnumHandle

[in] Handle returned by a previous call to the FindFirstUrlCacheEntry function.

Return Values

Returns TRUE if successful, or FALSE otherwise.

Requirements

OS Versions: Windows CE 2.12 and later.
Header: Wininet.h.
Link Library: Wininet.lib.

---------------------------------------------------------------------------------------------------------------------------------------------------

DeleteUrlCacheEntry

This function removes the file associated with the source name from the cache, if the file exists.

BOOL DeleteUrlCacheEntry( LPCTSTR lpszUrlName );

Parameters

lpszUrlName

[in] Address of a string variable that contains the cache entry source name. The name string must be unique and cannot contain escape characters.

Return Values

Returns TRUE if successful, or FALSE otherwise.

Requirements

OS Versions: Windows CE 2.12 and later.
Header: Wininet.h.
Link Library: Wininet.lib.

---------------------------------------------------------------------------------------------------------------------------------------------------
 
INTERNET_CACHE_ENTRY_INFO
Contains information about an entry in the Internet cache.
typedef struct _INTERNET_CACHE_ENTRY_INFO {
DWORD dwStructSize;
LPTSTR lpszSourceUrlName;
LPTSTR lpszLocalFileName;
DWORD CacheEntryType;
DWORD dwUseCount;
DWORD dwHitRate;
DWORD dwSizeLow;
DWORD dwSizeHigh;
FILETIME LastModifiedTime;
FILETIME ExpireTime;
FILETIME LastAccessTime;
FILETIME LastSyncTime;
LPBYTE lpHeaderInfo;
DWORD dwHeaderInfoSize;
LPTSTR lpszFileExtension;
union {
DWORD dwReserved;
DWORD dwExemptDelta;
}; } INTERNET_CACHE_ENTRY_INFO,
*LPINTERNET_CACHE_ENTRY_INFO;
Members
dwStructSize
Size of this structure, in bytes. This value can be used to help determine the version of the cache system.
lpszSourceUrlName
Pointer to a null-terminated string that contains the URL name. The string occupies the memory area at the end of this structure.
lpszLocalFileName
Pointer to a null-terminated string that contains the local file name. The string occupies the memory area at the end of this structure.
CacheEntryType
A bitmask indicating the type of cache entry and its properties. The cache entry types include: history entries (URLHISTORY_CACHE_ENTRY), cookie entries (COOKIE_CACHE_ENTRY), and normal cached content (NORMAL_CACHE_ENTRY).
This member can be zero or more of the following property flags, and cache type flags listed below.
Value
Meaning
EDITED_CACHE_ENTRY
Cache entry file that has been edited externally. This cache entry type is exempt from scavenging.
SPARSE_CACHE_ENTRY
Partial response cache entry.
STICKY_CACHE_ENTRY
Sticky cache entry that is exempt from scavenging for the amount of time specified by dwExemptDelta. The default value set by CommitUrlCacheEntry is one day.
TRACK_OFFLINE_CACHE_ENTRY
Not currently implemented.
TRACK_ONLINE_CACHE_ENTRY
Not currently implemented.
The following list contains the cache type flags.
Value
Meaning
COOKIE_CACHE_ENTRY
Cookie cache entry.
NORMAL_CACHE_ENTRY
Normal cache entry; can be deleted to recover space for new entries.
URLHISTORY_CACHE_ENTRY
Visited link cache entry.
dwUseCount
Current user count of the cache entry.
dwHitRate
Number of times the cache entry was retrieved.
dwSizeLow
Low-order portion of the file size, in TCHARs.
dwSizeHigh
High-order portion of the file size, in TCHARs.
LastModifiedTime
FILETIME structure that contains the last modified time of this URL, in Greenwich mean time format.
ExpireTime
FILETIME structure that contains the expiration time of this file, in Greenwich mean time format.
LastAccessTime
FILETIME structure that contains the last accessed time, in Greenwich mean time format.
LastSyncTime
FILETIME structure that contains the last time the cache was synchronized.
lpHeaderInfo
Pointer to a buffer that contains the header information. The buffer occupies the memory at the end of this structure.
dwHeaderInfoSize
Size of the lpHeaderInfo buffer, in TCHARs.
lpszFileExtension
Pointer to a string that contains the file extension used to retrieve the data as a file. The string occupies the memory area at the end of this structure.
dwReserved
Reserved. Must be zero.
dwExemptDelta
Exemption time from the last accessed time, in seconds.
Remarks
There is no cache entry size limit, so applications that need to enumerate the cache must be prepared to allocate variable-sized buffers. For more information, see Using Buffers.
Requirements
Client
Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.
Server
Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
Version
Requires Internet Explorer 3.0 or later.
Header
Declared in Wininet.h.
Unicode
Implemented as INTERNET_CACHE_ENTRY_INFOW (Unicode) and INTERNET_CACHE_ENTRY_INFOA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
 --------------------------------------------------------------------------------------------------------------------------------------------------
二、代码实现
#include  < stdio.h >
#include 
< windows.h >
#include 
< wininet.h >

// 获取IE上网缓存信息。如Cookie信息、Visited网址信息等
BOOL GetIECache()
{
    
int count = 0;
    HANDLE hCacheEnumHandle 
= NULL;
    LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry 
= NULL;
    DWORD dwSize 
= 4096;

    lpCacheEntry 
= (LPINTERNET_CACHE_ENTRY_INFO) new char[dwSize];
    lpCacheEntry
->dwStructSize = dwSize;


    
// URL search pattern (1st parameter) options are:  NULL ("*.*"), "cookie:", 
    
// or "visited:".
    hCacheEnumHandle = FindFirstUrlCacheEntry(
            
"visited:", lpCacheEntry, &dwSize);

    
if(hCacheEnumHandle != NULL)
    
{
        printf(
" %s ", lpCacheEntry->lpszSourceUrlName);
    }

    
else
    
{
        
switch(GetLastError())
        
{
            
case ERROR_INSUFFICIENT_BUFFER:
            lpCacheEntry 
= (LPINTERNET_CACHE_ENTRY_INFO) new char[dwSize];
            lpCacheEntry
->dwStructSize = dwSize;

            
// Repeat first step search with adjusted buffer, exit if not
            
// found again (in practice one buffer's size adustment is  
            
// always OK).
            hCacheEnumHandle = FindFirstUrlCacheEntry("visited:", lpCacheEntry, 
                                              
&dwSize);
            
if (hCacheEnumHandle != NULL) 
            
{
                count
++;
                printf(
" %d: %s ", count, lpCacheEntry->lpszSourceUrlName);
                
break;        
            }

            
else
            
{
                
// FindFirstUrlCacheEntry fails again, return.
                return FALSE; 
            }

            
default:
            
{
                FindCloseUrlCache(hCacheEnumHandle);
                
return FALSE;
            }

        }

    }


    
do 
    
{
         
// Notice that return values of FindNextUrlCacheEntry (BOOL) and 
         
// FindFirstUrlCacheEntry (HANDLE) are different.
         if (FindNextUrlCacheEntry(hCacheEnumHandle, lpCacheEntry, &dwSize))
         
{
             count
++;
                printf(
" %d: %s ", count, lpCacheEntry->lpszSourceUrlName);
         }

         
else
         
{
            
switch(GetLastError())
            
{
                
case ERROR_INSUFFICIENT_BUFFER:
                lpCacheEntry 
= 
                  (LPINTERNET_CACHE_ENTRY_INFO) 
new char[dwSize];
                lpCacheEntry
->dwStructSize = dwSize;

                
// Repeat next step search with adjusted buffer, exit if 
                
// error comes up again ((in practice one buffer's size 
                
// adustment is always OK).
                if (FindNextUrlCacheEntry(hCacheEnumHandle, lpCacheEntry, 
                                            
&dwSize)) 
                
{
                     count
++;
                    printf(
" %d: %s ", count, lpCacheEntry->lpszSourceUrlName);
                     
break;
                }

                
else
                
{
                    
// FindFirstUrlCacheEntry fails again, return.
                    FindCloseUrlCache(hCacheEnumHandle);
                    
return FALSE; 
                }

                
break;
                
case ERROR_NO_MORE_ITEMS:
                    FindCloseUrlCache(hCacheEnumHandle);
                    
return TRUE; 
                
default:
                    FindCloseUrlCache(hCacheEnumHandle);
                    
return FALSE;
            }

        }

    }
 while (TRUE);
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值