标签:
清除历史记录的文章很多,但是一般都不够全面。作者经过整理和收集一些资料,加以融合。得到了一个较全面的历史记录清除方法。
前言: 在本人用完计算机之后,往往不希望别人发现你做过什么,和浏览过什么网址。(特别是和多人共用一台机子时)。当然,你可以手工清理那些记录。 但那是多么繁杂的一件事啊。 我想没人愿意那样做。于是,我想到用一个软件来一次性完成上述工作。 清除历史记录的文章很多,但是一般都不够全面。本人经过整理和收集一些资料,加以融合。得到了一个较全面的历史记录清除方法。 在这里要指出代码能完成,要特别感谢朋友 xzhang左图便是本文例子程序的运行效果图,我们可以从中看到该例子具体能实现的清除内容。 大小:17K 下面我们通过代码看看具体是如何实现的。 |
首先: 在 stdafx.h中要加入: #include "atlbase.h" 设置->Link 要引入库 : Wininet.lib shlwapi.lib //在对话框的头文件中加入: 01. #include
"wininet.h" 02. #include
"UrlHist.h" 03. 04. #define
SWEEP_BUFFER_SIZE 10000 05. 06. public : 07. 08. enum DEL_CACHE_TYPE //要删除的类型。 09. { 10. File, //表示internet临时文件 11. Cookie //表示Cookie 12. }; //以下为一些辅助函数 ( 辅助函数的具体实现参见源代码中.限于篇幅不再给出 ) 01. BOOL DeleteUrlCache(DEL_CACHE_TYPE
type); 02. BOOL EmptyDirectory( LPCTSTR szPath, BOOL bDeleteDesktopIni
= FALSE, BOOL bWipeIndexDat
= FALSE); //清空一个目录 03. BOOL IsWindowsNT(); //判断系统 04. BOOL IsWindows2k(); 05. BOOL GetUserSid(PSID*
ppSid); 06. void GetSidString(PSID
pSid, LPTSTR szBuffer); 07. BOOL GetOldSD( HKEY hKey, LPCTSTR pszSubKey, BYTE **
pSD); 08. BOOL CreateNewSD(PSID
pSid, SECURITY_DESCRIPTOR* pSD, PACL* ppDacl); 09. BOOL RegSetPrivilege( HKEY hKey, LPCTSTR pszSubKey,
SECURITY_DESCRIPTOR* pSD, BOOL bRecursive); 10. BOOL WipeFile( LPCTSTR szDir, LPCTSTR szFile); //现在我们可以分别实现每项清除功能。 1、清除IE临时文件 1. TCHAR szPath[MAX_PATH]; 2. DeleteUrlCache(File); 3. if (SHGetSpecialFolderPath(NULL,
szPath, CSIDL_INTERNET_CACHE, FALSE)) 4. { //得到临时目录,并清空它. 5. EmptyDirectory(szPath); 6. } 清除IE临时文件的另外一个途径是直接调用Wininet函数,请看下面用于清除IE临时文件的函数 01. BOOL DelTempFiles() 02. { 03. BOOL bResult
= FALSE; 04. BOOL bDone
= FALSE; 05. LPINTERNET_CACHE_ENTRY_INFO
lpCacheEntry = NULL; 06. 07. DWORD dwTrySize,
dwEntrySize = 4096; //
start buffer size 08. HANDLE hCacheDir
= NULL; 09. DWORD dwError
= ERROR_INSUFFICIENT_BUFFER; 10. 11. do 12. { 13. switch (dwError) 14. { 15. //
need a bigger buffer 16. case ERROR_INSUFFICIENT_BUFFER: 17. delete []
lpCacheEntry; 18. lpCacheEntry
= (LPINTERNET_CACHE_ENTRY_INFO) new char [dwEntrySize]; 19. lpCacheEntry->dwStructSize
= dwEntrySize; 20. dwTrySize
= dwEntrySize; 21. BOOL bSuccess; 22. if (hCacheDir
== NULL) 23. 24. bSuccess
= (hCacheDir 25. =
FindFirstUrlCacheEntry(NULL, lpCacheEntry, 26. &dwTrySize))
!= NULL; 27. else 28. bSuccess
= FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize); 29. 30. if (bSuccess) 31. dwError
= ERROR_SUCCESS; 32. else 33. { 34. dwError
= GetLastError(); 35. dwEntrySize
= dwTrySize; //
use new size returned 36. } 37. break ; 38. 39. //
we are done 40. case ERROR_NO_MORE_ITEMS: 41. bDone
= TRUE; 42. bResult
= TRUE; 43. break ; 44. 45. //
we have got an entry 46. case ERROR_SUCCESS: 47. 48. //
don‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘t delete cookie entry 49. if (!(lpCacheEntry->CacheEntryType
& COOKIE_CACHE_ENTRY)) 50. 51. DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName); 52. 53. //
get ready for next entry 54. dwTrySize
= dwEntrySize; 55. if (FindNextUrlCacheEntry(hCacheDir,
lpCacheEntry, &dwTrySize)) 56. dwError
= ERROR_SUCCESS; 57. 58. else 59. { 60. dwError
= GetLastError(); 61. dwEntrySize
= dwTrySize; //
use new size returned 62. } 63. break ; 64. 65. //
unknown error 66. default : 67. bDone
= TRUE; 68. break ; 69. } 70. 71. if (bDone) 72. { 73. delete []
lpCacheEntry; 74. if (hCacheDir) 75. FindCloseUrlCache(hCacheDir); 76. 77. } 78. } while (!bDone); 79. return bResult; 80. } 2、Cookie的清除 1. TCHAR szPath[MAX_PATH]; 2. DeleteUrlCache(Cookie); 3. if (SHGetSpecialFolderPath(NULL,
szPath, CSIDL_COOKIES, FALSE)) 4. { //得到目录,并清空 5. EmptyDirectory(szPath); 6. } 3、浏览器地址栏历史地址的清除 1. SHDeleteKey(HKEY_CURRENT_USER, 2. _T( "Software\\Microsoft\\Internet
Explorer\\TypedURLs" )); 4、清除表单自动完成历史记录 01. CString
sKey; 02. DWORD dwRet; 03. 04. if (IsWindows2k()
|| IsWindowsNT()) //先判断系统 05. { 06. CString
sBaseKey; 07. SECURITY_DESCRIPTOR
NewSD; 08. BYTE *
pOldSD; 09. PACL
pDacl = NULL; 10. PSID
pSid = NULL; 11. TCHAR szSid[256]; 12. if (GetUserSid(&pSid)) 13. { 14. //get
the hiden key name 15. GetSidString(pSid,
szSid); 16. 17. sKey
= _T( "Software\\Microsoft\\Protected
Storage System Provider\\" ); 18. sKey
+= szSid; 19. 20. //get
old SD 21. sBaseKey
= sKey; 22. GetOldSD(HKEY_CURRENT_USER,
sBaseKey, &pOldSD); 23. 24. //set
new SD and then clear 25. if (CreateNewSD(pSid,
&NewSD, &pDacl)) 26. { 27. RegSetPrivilege(HKEY_CURRENT_USER,
sKey, &NewSD, FALSE); 28. 29. sKey
+= _T( "\\Data" ); 30. RegSetPrivilege(HKEY_CURRENT_USER,
sKey, &NewSD, FALSE); 31. 32. sKey
+= _T( "\\e161255a-37c3-11d2-bcaa-00c04fd929db" ); 33. RegSetPrivilege(HKEY_CURRENT_USER,
sKey, &NewSD, TRUE); 34. 35. dwRet
= SHDeleteKey(HKEY_CURRENT_USER, sKey); 36. } 37. 38. if (pDacl
!= NULL) 39. HeapFree(GetProcessHeap(),
0, pDacl); 40. 41. //restore
old SD 42. if (pOldSD) 43. { 44. RegSetPrivilege(HKEY_CURRENT_USER,
sBaseKey, 45. (SECURITY_DESCRIPTOR*)pOldSD,
FALSE); 46. delete pOldSD; 47. } 48. } 49. if (pSid) 50. HeapFree(GetProcessHeap(),
0, pSid); 51. } 52. 53. //win9x 54. DWORD dwSize
= MAX_PATH; 55. TCHAR szUserName[MAX_PATH]; 56. GetUserName(szUserName,
&dwSize); 57. 58. sKey
= _T( "Software\\Microsoft\\Protected
Storage System Provider\\" ); 59. sKey
+= szUserName; 60. sKey
+= _T( "\\Data\\e161255a-37c3-11d2-bcaa-00c04fd929db" ); 61. dwRet
= SHDeleteKey(HKEY_LOCAL_MACHINE, sKey); 5、清除自动密码历史记录 1. SHDeleteKey(HKEY_CURRENT_USER, 2. _T( "Software\\Microsoft\\Internet
Explorer\\IntelliForms" )); 6、清收藏夹中的内容 1. TCHAR szPath[MAX_PATH]; 2. if (SHGetSpecialFolderPath(NULL,
szPath, CSIDL_FAVORITES, FALSE)) 3. { //得到目录,并清空 4. EmptyDirectory(szPath); 5. } 7、清RAS自动拨号历史记录 1. SHDeleteKey(HKEY_CURRENT_USER, 2. _T( "Software\\Microsoft\\RAS
Autodial\\Addresses" )); 8、清系统临时文件夹 1. TCHAR szPath[MAX_PATH]; 2. if (GetTempPath(MAX_PATH,
szPath)) //得到系统临时目录 3. { 4. EmptyDirectory(szPath,
TRUE); 5. } 9、清空回收站 1. SHEmptyRecycleBin(NULL,
NULL, 2. 3. SHERB_NOCONFIRMATION
| SHERB_NOPROGRESSUI | SHERB_NOSOUND); 10、清除"运行"中的自动匹配历史记录 1. SHDeleteKey(HKEY_CURRENT_USER, 2. _T("Software\\Microsoft\\Windows\\ 3. CurrentVersion\\Explorer\\RunMRU")); 11、清"文档"中的历史记录 1. TCHAR szPath[MAX_PATH]; 2. if (SHGetSpecialFolderPath(NULL,
szPath, CSIDL_RECENT, FALSE)) 3. { 4. EmptyDirectory(szPath); 5. } 6. SHDeleteKey(HKEY_CURRENT_USER, 7. _T("Software\\Microsoft\\Windows\\CurrentVersion 8. \\Explorer\\RecentDocs")); 12、清除上次登陆用户记录 01. SHDeleteValue(HKEY_CURRENT_USER, 02. _T("Software\\Microsoft\\Windows
NT\\ 03. CurrentVersion\\Winlogon"), 04. _T( "DefaultUserName" )); 05. SHDeleteValue(HKEY_CURRENT_USER, 06. _T("Software\\Microsoft\\Windows
NT\\ 07. CurrentVersion\\Winlogon"), 08. _T( "AltDefaultUserName" )); 09. SHDeleteValue(HKEY_LOCAL_MACHINE, 10. _T("Software\\Microsoft\\Windows\\ 11. CurrentVersion\\Winlogon"), 12. _T( "DefaultUserName" )); 13、清除"查找文件"自动匹配历史记录 01. SHDeleteKey(HKEY_CURRENT_USER, 02. _T("Software\\Microsoft\\Windows\\ 03. CurrentVersion\\Explorer\\Doc
Find Spec 04. MRU")); 05. SHDeleteKey(HKEY_CURRENT_USER, 06. _T("Software\\Microsoft\\Internet
Explorer 07. \\Explorer
Bars\\{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1} 08. \\ContainingTextMRU")); 09. SHDeleteKey(HKEY_CURRENT_USER, 10. _T("Software\\Microsoft\\Internet
Explorer 11. \\Explorer
Bars\\{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1} 12. \\FilesNamedMRU")); 14、清除"查找计算机"自动匹配历史记录 1. SHDeleteKey(HKEY_CURRENT_USER, 2. _T("Software\\Microsoft\\Windows\\CurrentVersion 3. \\Explorer\\FindComputerMRU")); 4. SHDeleteKey(HKEY_CURRENT_USER, 5. _T("Software\\Microsoft\\Internet
Explorer\\Explorer Bars 6. \\{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1} 7. \\ComputerNameMRU")); 15、清除网络联接历史记录 1. TCHAR szPath[MAX_PATH]; 2. if (SHGetSpecialFolderPath(NULL,
szPath, CSIDL_NETHOOD, FALSE)) 3. { //得到目录,并清空 4. EmptyDirectory(szPath); 5. } 16、清远程登录历史记录 01. CString
sKey; 02. for ( int i=1;
i<=8; i++) 03. { 04. sKey.Format(_T( "Machine%d" ),
i); 05. SHDeleteValue(HKEY_CURRENT_USER, 06. _T( "Software\\Microsoft\\Telnet" ),
sKey); 07. 08. sKey.Format(_T( "Service%d" ),
i); 09. SHDeleteValue(HKEY_CURRENT_USER, 10. _T( "Software\\Microsoft\\Telnet" ),
sKey); 11. 12. sKey.Format(_T( "TermType%d" ),
i); 13. SHDeleteValue(HKEY_CURRENT_USER, 14. _T( "Software\\Microsoft\\Telnet" ),
sKey); 15. } 16. SHDeleteValue(HKEY_CURRENT_USER, 17. _T( "Software\\Microsoft\\Telnet" ),
_T( "LastMachine" )); 18. SHDeleteValue(HKEY_CURRENT_USER, 19. _T( "Software\\Microsoft\\Telnet" ),
_T( "LastService" )); 20. SHDeleteValue(HKEY_CURRENT_USER, 21. _T( "Software\\Microsoft\\Telnet" ),
_T( "LastTermType" )); 17、清浏览网址历史记录 下面这个函数可以用于清除网址历史记录 01. #include
"SHLGUID.H" 02. HRESULT ClearHistory() 03. { 04. HRESULT hr; 05. CoInitialize(NULL); 06. { 07. IUrlHistoryStg2*
pUrlHistoryStg2 = NULL; 08. hr=
CoCreateInstance(CLSID_CUrlHistory,NULL,1, IID_IUrlHistoryStg2,( void **)&pUrlHistoryStg2); 09. if (SUCCEEDED(hr)) 10. { 11. hr
= pUrlHistoryStg2->ClearHistory(); 12. pUrlHistoryStg2->Release(); 13. } 14. } 15. CoUninitialize(); 16. return hr; 17. } // 如果上面代码不能清 // 则有下面的,不完美,但能工作. 01. TCHAR szPath[MAX_PATH]; 02. GetWindowsDirectory(szPath,
MAX_PATH); 03. _tcscat(szPath,
_T( "\\History" )); 04. EmptyDirectory(szPath,
FALSE, TRUE); 05. 06. if (SHGetSpecialFolderPath(NULL,
szPath, CSIDL_HISTORY, FALSE)) 07. { 08. EmptyDirectory(szPath,
FALSE, TRUE); 09. } |
标签:
原文地址:http://blog.csdn.net/jiangqin115/article/details/45287295