您的位置:首页 > 其它

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

2006-12-26 15:36 651 查看
一、主要用到以下几个API:
1、FindFirstUrlCacheEntry
2、FindNextUrlCacheEntry
3、FindCloseUrlCache
下面的内容摘自MSDN:
-------------------------------------------------------------------------------------------------------------------------------------------------------

[align=left]FindFirstUrlCacheEntry[/align]
[align=left]Begins the enumeration of the Internet cache.[/align]
[align=left]HANDLE FindFirstUrlCacheEntry( LPCTSTR lpszUrlSearchPattern, LPINTERNET_CACHE_ENTRY_INFO lpFirstCacheEntryInfo, LPDWORD lpcbCacheEntryInfo ); [/align]
[align=left]Parameters[/align]
[align=left]lpszUrlSearchPattern[/align]
[align=left][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. [/align]
[align=left]lpFirstCacheEntryInfo[/align]
[align=left][out] Pointer to an INTERNET_CACHE_ENTRY_INFO structure. [/align]
[align=left]lpcbCacheEntryInfo[/align]
[align=left][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. [/align]
[align=left]Return Value[/align]
[align=left]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.[/align]
[align=left]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.[/align]
[align=left]Remarks[/align]
[align=left]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.[/align]
[align=left]Requirements[/align]

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

[align=left]FindNextUrlCacheEntry[/align]
[align=left]Retrieves the next entry in the Internet cache.[/align]
[align=left]BOOLAPI FindNextUrlCacheEntry( HANDLE hEnumHandle, LPINTERNET_CACHE_ENTRY_INFO lpNextCacheEntryInfo, LPDWORD lpcbCacheEntryInfo ); [/align]
[align=left]Parameters[/align]
[align=left]hEnumHandle[/align]
[align=left][in] Handle to the enumeration obtained from a previous call to FindFirstUrlCacheEntry. [/align]
[align=left]lpNextCacheEntryInfo[/align]
[align=left][out] Pointer to an INTERNET_CACHE_ENTRY_INFO structure that receives information about the cache entry. [/align]
[align=left]lpcbCacheEntryInfo[/align]
[align=left][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. [/align]
[align=left]Return Value[/align]
[align=left]Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. Possible error values include the following. [/align]
[align=center]Return code[/align]
[align=center]Description[/align]
[align=left]ERROR_INSUFFICIENT_BUFFER[/align]
[align=left]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.[/align]
[align=left]ERROR_NO_MORE_ITEMS[/align]
[align=left]The enumeration completed.[/align]
[align=left]Remarks[/align]
[align=left]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.[/align]
[align=left]Requirements[/align]
[align=center]Client[/align]
[align=left]Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.[/align]
[align=center]Server[/align]
[align=left]Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.[/align]
[align=center]Version[/align]
[align=left]Requires Internet Explorer 3.0 or later.[/align]
[align=center]Header[/align]
[align=left]Declared in Wininet.h.[/align]
[align=center]Library[/align]
[align=left]Use Wininet.lib.[/align]
[align=center]DLL[/align]
[align=left]Requires Wininet.dll. [/align]
[align=center]Unicode[/align]
[align=left]Implemented as FindNextUrlCacheEntryW (Unicode) and FindNextUrlCacheEntryA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.[/align]
---------------------------------------------------------------------------------------------------------------------------------------------------

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.

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

[align=left]INTERNET_CACHE_ENTRY_INFO[/align]
[align=left]Contains information about an entry in the Internet cache.[/align]
[align=left]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;[/align]
[align=left]Members[/align]
[align=left]dwStructSize[/align]
[align=left]Size of this structure, in bytes. This value can be used to help determine the version of the cache system. [/align]
[align=left]lpszSourceUrlName[/align]
[align=left]Pointer to a null-terminated string that contains the URL name. The string occupies the memory area at the end of this structure. [/align]
[align=left]lpszLocalFileName[/align]
[align=left]Pointer to a null-terminated string that contains the local file name. The string occupies the memory area at the end of this structure. [/align]
[align=left]CacheEntryType[/align]
[align=left]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).[/align]
[align=left]This member can be zero or more of the following property flags, and cache type flags listed below.[/align]
[align=center]Value[/align]
[align=center]Meaning[/align]
[align=left]EDITED_CACHE_ENTRY[/align]
[align=left]Cache entry file that has been edited externally. This cache entry type is exempt from scavenging.[/align]
[align=left]SPARSE_CACHE_ENTRY[/align]
[align=left]Partial response cache entry.[/align]
[align=left]STICKY_CACHE_ENTRY[/align]
[align=left]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. [/align]
[align=left]TRACK_OFFLINE_CACHE_ENTRY[/align]
[align=left]Not currently implemented.[/align]
[align=left]TRACK_ONLINE_CACHE_ENTRY[/align]
[align=left]Not currently implemented.[/align]
[align=left]The following list contains the cache type flags.[/align]
[align=center]Value[/align]
[align=center]Meaning[/align]
[align=left]COOKIE_CACHE_ENTRY[/align]
[align=left]Cookie cache entry.[/align]
[align=left]NORMAL_CACHE_ENTRY[/align]
[align=left]Normal cache entry; can be deleted to recover space for new entries.[/align]
[align=left]URLHISTORY_CACHE_ENTRY[/align]
[align=left]Visited link cache entry.[/align]
[align=left]dwUseCount[/align]
[align=left]Current user count of the cache entry. [/align]
[align=left]dwHitRate[/align]
[align=left]Number of times the cache entry was retrieved. [/align]
[align=left]dwSizeLow[/align]
[align=left]Low-order portion of the file size, in TCHARs. [/align]
[align=left]dwSizeHigh[/align]
[align=left]High-order portion of the file size, in TCHARs. [/align]
[align=left]LastModifiedTime[/align]
[align=left]FILETIME structure that contains the last modified time of this URL, in Greenwich mean time format. [/align]
[align=left]ExpireTime[/align]
[align=left]FILETIME structure that contains the expiration time of this file, in Greenwich mean time format. [/align]
[align=left]LastAccessTime[/align]
[align=left]FILETIME structure that contains the last accessed time, in Greenwich mean time format. [/align]
[align=left]LastSyncTime[/align]
[align=left]FILETIME structure that contains the last time the cache was synchronized. [/align]
[align=left]lpHeaderInfo[/align]
[align=left]Pointer to a buffer that contains the header information. The buffer occupies the memory at the end of this structure. [/align]
[align=left]dwHeaderInfoSize[/align]
[align=left]Size of the lpHeaderInfo buffer, in TCHARs. [/align]
[align=left]lpszFileExtension[/align]
[align=left]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. [/align]
[align=left]dwReserved[/align]
[align=left]Reserved. Must be zero. [/align]
[align=left]dwExemptDelta[/align]
[align=left]Exemption time from the last accessed time, in seconds. [/align]
[align=left]Remarks[/align]
[align=left]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.[/align]
[align=left]Requirements[/align]
[align=center]Client[/align]
[align=left]Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.[/align]
[align=center]Server[/align]
[align=left]Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.[/align]
[align=center]Version[/align]
[align=left]Requires Internet Explorer 3.0 or later.[/align]
[align=center]Header[/align]
[align=left]Declared in Wininet.h.[/align]
[align=center]Unicode[/align]
[align=left]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.[/align]
--------------------------------------------------------------------------------------------------------------------------------------------------

二、代码实现


#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);


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: