可以参考这个链接静默清除IE cookie
https://www.codeproject.com/Articles/15319/A-Cleanup-API-for-Windows
__declspec( dllexport ) BOOL Delete_IECookies(BOOL bDeleteCookies,
BOOL bDeleteCookiesIndex)
{
TCHAR szUserProfile[200];
TCHAR szFilePath[200];
HANDLE hCacheEnumHandle = NULL;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;
DWORD dwSize = 4096; // initial buffer size
// Delete index.dat if requested. Be sure that index.dat is not locked.
if(bDeleteCookiesIndex)
{
// Retrieve from environment user profile path.
ExpandEnvironmentStrings("%userprofile%", szUserProfile,
sizeof(szUserProfile));
wsprintf(szFilePath, "%s%s", szUserProfile, "\\Cookies\\index.dat");
DeleteFile(szFilePath);
if(!bDeleteCookies) return TRUE;
}
// Enable initial buffer size for cache entry structure.
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwSize];
lpCacheEntry->dwStructSize = dwSize;
// URL search pattern (1st parameter) options are: "cookie:", "visited:",
// or NULL ("*.*").
hCacheEnumHandle = FindFirstUrlCacheEntry(_T("cookie:") /* in */,
lpCacheEntry /* out */, &dwSize /* in, out */);
// First, obtain handle to internet cache with FindFirstUrlCacheEntry
// for late use with FindNextUrlCacheEntry.
if(hCacheEnumHandle != NULL)
{
DeleteUrlCacheEntry(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(NULL, lpCacheEntry,
&dwSize);
if(hCacheEnumHandle != NULL)
{
DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);
break;
}
else
{
// FindFirstUrlCacheEntry fails again, return.
return FALSE;
}
default:
FindCloseUrlCache(hCacheEnumHandle);
return FALSE;
}
}
// Next, use hCacheEnumHandle obtained from the previous step to delete
// subsequent items of cache.
do
{
// Notice that return values of FindNextUrlCacheEntry (BOOL) and
// FindFirstUrlCacheEntry (HANDLE) are different.
if(FindNextUrlCacheEntry(hCacheEnumHandle, lpCacheEntry, &dwSize))
{
DeleteUrlCacheEntry(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))
{
DeleteUrlCacheEntry(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);
return FALSE; // never here
}