Use VC to clear browsing traces
[Author: Tang can and Yu Zhicheng: 12:10:21]
Browsing on the computer always leaves some traces. Manual cleanup is really annoying. So let's use programming to clear browsing traces once and for all.
1. Clear files in the specified directory
As we all know, most of the "spam" are placed in the specified folder, you just need to delete these files.
Use the deletefile function in the Windows API to do this. We can make it a perfect function to delete the selected types of files in the specified folder. The function expansion code is as follows:
Void delmypointfile (lpstr name, lpstr currentpath) { // Delete the specified file in the specified path. Wildcards are supported. // Name: the object to be deleted; currentpath: the path of the object to be deleted. Win32_find_data filedata; Handle hsearch; Char szhome [max_path]; // Char szfile [max_path]; DWORD rightwrong; // HDC mydiadc; DWORD namelength; // Current program path Rightwrong = getcurrentdirectory (max_path, szhome ); Rightwrong = setcurrentdirectory (currentpath ); // Save the program execution path and set the current path to the path to be searched. Hsearch = findfirstfile (name, & filedata ); If (hsearch! = Invalid_handle_value) { Namelength = lstrlen (filedata. cfilename ); Deletefile (filedata. cfilename ); While (findnextfile (hsearch, & filedata )) { // Find the next file and find one to delete Namelength = lstrlen (filedata. cfilename ); Deletefile (filedata. cfilename ); } Findclose (hsearch ); // Close the search handle } Rightwrong = setcurrentdirectory (szhome ); } |
With this function, you can use the following code to clear document menus, system temporary directories, and IE temporary directories.
Char windowrecentpath [] = "// recent "; Char windowtemp [] = "// Temp "; Char character wietemp [] = "// Temporary Internet Files "; Char windowcookie [] = "// cookies "; Char szwindowspath [max_path]; Char szdelpath [max_path]; ... Getwindowsdirectory (szwindowspath, max_path ); Lstrcpy (szdelpath, szwindowspath ); Lstrcat (szdelpath, windowrecentpath ); // Delete the list of objects recently used by the window Delmypointfile ("*. *", szdelpath ); Lstrcpy (szdelpath, szwindowspath ); Lstrcat (szdelpath, windowtemp ); // Delete the temporary window file Delmypointfile ("*. *", szdelpath ); Lstrcpy (szdelpath, szwindowspath ); Lstrcat (szdelpath, javaswietemp ); // Delete the temporary window IE File Delmypointfile ("*. *", szdelpath ); |
2. Clear "history"
IE's "History" has been a headache, even if you set "History" to zero days, you can also save the content of the day; try to delete it with a file, however, this cannot be achieved because the file is in the loading mode. You cannot find the available APIs in msdn. Fortunately, ie's own cleanup function can do this. IE is a typical COM component. We can call its component module to clear the "History" directly ".
Hresult clearhistory () { // Create the iurlhistorystg2 component pointer Iurlhistorystg2 * purlhistorystg2 = NULL; // Initialize the com Library Coinitialize (null ); // Create a customer object Hresult hR = cocreateinstance (clsid_curlhistory, null, clsctx_inproc, iid_iurlhistorystg2, (void) & purlhistorystg2 ); If (succeeded (HR )) { // Interface call HR = purlhistorystg2-> clearhistory (); Purlhistorystg2-> release (); } // Close the com library connection Couninitialize (); Return hr; } |
3. Clear the drop-down cache list
The IE drop-down cache list saves the web site you browsed at any time, but the above Code cannot be cleared. The Windows API provides three functions: findnexturlcacheentry, deleteurlcacheentry, and findfirsturlcacheentry, which are used for cleanup. In Windows 9x, there is a more lazy way to delete the Registry directly. The Code is as follows:
Void delregcache () { // Delete the record in the IE cache saved in the Registry Lpcstr rootkey = "HKEY_CURRENT_USER "; Lpcstr subkey = "software // Microsoft // Internet Explorer // typedurls "; Regdeletekey (HKEY_CURRENT_USER, subkey ); } Delete cookie Cookies are stored in the cookies subdirectory of the system directory. If IE is not enabled, you can delete them directly. If you open IE, because it will save part of it in the memory, you can use the following code to delete it. Internetsetoption (0, internet_option_end_browser_session, 0, 0 ); Lstrcpy (szdelpath, szwindowspath ); Lstrcat (szdelpath, windowcookie ); // Delete the temporary window IE File Delmypointfile ("*. *", szdelpath ); |
The above code is run in VC ++ 6.0 and Windows 98, which can meet most of the daily usage requirements. However, the delmypointfile function in the above Code is relatively simple. Only files under the directory can be deleted, and subdirectories are powerless. Interested readers can compile a recursive process to improve its functions.
1 2 next page