This article supporting the source code download
Objective:
After I use the computer, often do not want others to find out what you have done, and browse what URLs. (especially when sharing a machine with more than one person). Of course, you can clean those records by hand. But what a complicated thing it is. I don't think anyone would like to do that. So, I thought of using a software to complete the above work at once.
There are many articles that erase history, but they are generally not comprehensive enough. I have collated and collected some information to integrate. A more comprehensive method of historical record removal is obtained.
The following figure is the example of the operation of this sample program, we can see this example of the specific implementation of the removal of the content.
Let's take a look at the code below to see how it is implemented.
First: In the stdafx.h to add: #include "atlbase.h"
Set->link to introduce libraries: Wininet.lib Shlwapi.lib
In the header file of the dialog box, add:
#include "wininet.h"
#include "UrlHist.h"
#define SWEEP_BUFFER_SIZE 10000
public:
enum DEL_CACHE_TYPE //要删除的类型。
{
File,//表示internet临时文件
Cookie //表示Cookie
};
The following are some of the auxiliary functions (the concrete implementation of the auxiliary functions see source code. No longer given space)
BOOL DeleteUrlCache(DEL_CACHE_TYPE type);
BOOL EmptyDirectory(LPCTSTR szPath, BOOL bDeleteDesktopIni = FALSE, BOOL bWipeIndexDat = FALSE);//清空一个目录
BOOL IsWindowsNT();//判断系统
BOOL IsWindows2k();
BOOL GetUserSid(PSID* ppSid);
void GetSidString(PSID pSid, LPTSTR szBuffer);
BOOL GetOldSD(HKEY hKey, LPCTSTR pszSubKey, BYTE** pSD);
BOOL CreateNewSD(PSID pSid, SECURITY_DESCRIPTOR* pSD, PACL* ppDacl);
BOOL RegSetPrivilege(HKEY hKey, LPCTSTR pszSubKey, SECURITY_DESCRIPTOR* pSD, BOOL bRecursive);
BOOL WipeFile(LPCTSTR szDir, LPCTSTR szFile);
Now we can implement each of the cleanup features individually.
1, clear IE temporary files
TCHAR szPath[MAX_PATH];
DeleteUrlCache(File);
if (SHGetSpecialFolderPath(NULL, szPath, CSIDL_INTERNET_CACHE, FALSE))
{ //得到临时目录,并清空它.
EmptyDirectory(szPath);
}
Another way to clear ie temporary files is to call the WinInet function directly, see the following function to clear the IE temporary file
BOOL Deltempfiles ()
{
BOOL bresult = FALSE;
BOOL bdone = FALSE;
Lpinternet_cache_entry_info lpcacheentry = NULL;
DWORD dwtrysize, dwentrysize = 4096; Start buffer size
HANDLE hcachedir = NULL;
DWORD dwerror = Error_insufficient_buffer;
Todo
{
Switch (dwerror)
{
Need a bigger buffer
Case ERROR_INSUFFICIENT_BUFFER:
delete [] lpcacheentry;
Lpcacheentry = (lpinternet_cache_entry_info) new char[dwentrysize];
Lpcacheentry->dwstructsize = dwentrysize;
Dwtrysize = dwentrysize;
BOOL bsuccess;
if (Hcachedir = NULL)
bsuccess = (hcachedir
= Findfirsturlcacheentry (NULL, Lpcacheentry,
&dwtrysize))!= NULL;
Else
bsuccess = FindNextUrlCacheEntry (Hcachedir, Lpcacheentry, &dwtrysize);
if (bsuccess)
dwerror = ERROR_SUCCESS;
Else
{
dwerror = GetLastError ();
Dwentrysize = dwtrysize; Use new size returned
}
Break
We are done
Case ERROR_NO_MORE_ITEMS:
Bdone = TRUE;
Bresult = TRUE;
Break
We have got an entry
Case ERROR_SUCCESS:
Don ' ' ' ' ' ' ' ' ' t Delete cookie entry
if (!) ( Lpcacheentry->cacheentrytype & Cookie_cache_entry))
Deleteurlcacheentry (Lpcacheentry->lpszsourceurlname);
Get ready for next entry
Dwtrysize = dwentrysize;
if (FindNextUrlCacheEntry (Hcachedir, Lpcacheentry, &dwtrysize))
dwerror = ERROR_SUCCESS;
Else
{
dwerror = GetLastError ();
Dwentrysize = dwtrysize; Use new size returned
}
Break
Unknown error
Default
Bdone = TRUE;
Break
}
if (bdone)
{
delete [] lpcacheentry;
if (Hcachedir)
Findcloseurlcache (Hcachedir);
}
while (!bdone);
return bresult;
}