-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClearCache.cpp
103 lines (89 loc) · 2.6 KB
/
ClearCache.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//////////////////////////////////////////////////////////////////////
// Classe : CacheEntry
// Resume : Clear Selected Cache Entry
////////////
#include "stdafx.h"
#include "ClearCache.h"
#include "CacheInfo.h"
#include "CacheEntry.h"
#include <shlguid.h>
#include <urlhist.h>
extern CString GetTime(FILETIME ft);
//////////////////////////////////////////////////////////////////////
// Methode : CClearCache
// Resume : Constructeur
// In : None
// Out : None
//////////////////////////////////////////////////////////////////////
CClearCache::CClearCache()
{
}
//////////////////////////////////////////////////////////////////////
// Methode : ~CClearCache
// Resume : Destructor
// In : None
// Out : None
//////////////////////////////////////////////////////////////////////
CClearCache::~CClearCache()
{
}
//////////////////////////////////////////////////////////////////////
// Methode : Clear
// Resume : Clear entries in a container
// In : None
// Out : None
//////////////////////////////////////////////////////////////////////
void CClearCache::Clear(LPSTR lpszContainer)
{
CCacheEntry CacheEntry;
LPINTERNET_CACHE_ENTRY_INFO pInfo = CacheEntry.First(lpszContainer);
nEntries = 0;
nEntriesDeleted = 0;
while (pInfo)
{
nEntries++;
nEntriesDeleted++;
DelCacheEntry(pInfo);
pInfo = CacheEntry.Next();
}
if (lstrcmp(lpszContainer, HISTORY_CACHE_PREFIX) == 0)
{
RegDeleteKey(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Internet Explorer\\TypedURLs"));
RegDeleteKey(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU"));
IUrlHistoryStg2* pHistory; // We need this interface for clearing the history.
HRESULT hr;
DWORD cRef;
CoInitialize(NULL);
// Load the correct Class and request IUrlHistoryStg2
hr = CoCreateInstance(CLSID_CUrlHistory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IUrlHistoryStg2,
reinterpret_cast<void **>(&pHistory));
if (SUCCEEDED(hr))
{
// Clear the IE History
hr = pHistory->ClearHistory();
}
// Release our reference to the
cRef = pHistory->Release();
CoUninitialize();
}
}
//////////////////////////////////////////////////////////////////////
// Methode : DelCacheEntry
// Resume : Delete specified cache entry
// In : None
// Out : None
//////////////////////////////////////////////////////////////////////
bool CClearCache::DelCacheEntry(INTERNET_CACHE_ENTRY_INFO* pInfo)
{
return (::DeleteUrlCacheEntry(pInfo->lpszSourceUrlName) ? true : false);
}
void CClearCache::ClearAll()
{
Clear(TEMPORARY_CACHE_PREFIX);
Clear(HISTORY_CACHE_PREFIX);
Clear(COOKIE_CACHE_PREFIX);
_tprintf(_T("All Cache Cleared\n"));
}