This article is mainly about the project "personal computer use record removal Software" series of articles on the elimination of browser cookies, ie temporary files, recent use history, and so on. The basic idea of this article is to first learn about the history of the Internet in Windows common file path, The file Delete method is used to delete the contents of the file, but many files cannot be read; The final solution is to remove the caching functionality with RunDll32.exe Internet implementation. A. IE History file path
There are specified folder stores in Internet Explorer to record all information, including IE cache files, cookies files, recently browsed history, visited URLs, address bar URLs and IE forms/Password records, temporary files, etc. before you talk about removing IE cache, Briefly introduce cookies, Internet temp files, and file paths for IE history.
The location of the cookie in 1.Windows is "C:\Users\dell\AppData\Roaming\Microsoft\Windows\Cookies". The cookie records the user ID, the password, the browser's Web page, the dwell time, and so on. The following figure shows:
The Internet temporary file location in 2.Windows is "C:\Users\dell\AppData\Local\Microsoft\Windows\Temporary Internet Files". It holds the content of the most recently browsed pages (page | image | Media copy, etc.) for quick query and speed improvement.
The IE history location in 3.Windows is "C:\Users\dell\AppData\Local\Microsoft\Windows\History", and the history is the site address of the most recent time, which is stored in time and site. The following figure shows :
ie usually clears history, including download history, form data, password, ActiveX data, as follows:
two. Delete with file delete
Obtain the temporary Internet files file (Environment.getfolderpath) via Environment.SpecialFolder.InternetCache ( Internet temporary files), and get the. dat file path.
Gets the IE temporary file
private void Button2_Click (object sender, EventArgs e)
{
listBox1.Items.Clear ();
String dirpath = Environment.getfolderpath (Environment.SpecialFolder.InternetCache);
This.textBox1.Text = Dirpath.tostring ();
DirectoryInfo dir = new DirectoryInfo (dirpath);
Traverse all folders to display. dat files
foreach (FileInfo file in dir.) GetFiles ("*.jpg", searchoption.alldirectories))
{
try
{
listBox1.Items.Add (file. DirectoryName + "\" + file);
File. Delete ();
}
catch (Exception msg) //exception handling
{
MessageBox.Show (msg. message);}}
references the namespace using System.IO, and the results of the run are as follows:
As a result, it appears that emptying all files under this folder enables the removal of temporary Internet files, but using File.delete (FileName) to delete files in a folder will encounter "the file is in use by another process so the process cannot access this file" or "File Access Denied" Because the temporary Internet files directory is a system folder, you cannot read some files.
(The resource about IE temporary files get view Delete, for everyone to learn http://download.csdn.net/detail/jee89731/3465688) Three. Call Rundll32.exe implementation
The use of RunDll32.exe to run Internet Options corresponding DLL files, to clear the IE cache (Internet temporary files, Cookies, browser history, form records, user name password, etc.).
< a >.rundll32.exe
Rundll32.exe (Running a 32-bit DLL file) is the function of executing the internal function in the DLL file, invoking the dynamic-linker library by command line, with the command line using the following method: Rundll32.exe Dllname,functionname [ Arguments]. (where dllname is required to execute DLL file name, functionname is the specific reference function that executes DLL file, [Arguments] is the specific parameter of the derivation function).
the CTRL+R call runs the input instruction execution and runs the appropriate operation. The Rundll32.exe shell32.dll,Control_RunDLL function is to perform the display control Panel. One of the things about clearing IE caching is as follows:
1.History (historical record)
RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 1
//2.cookies
RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 2
//3.temporary Internet Files (Internet temp file)
RunDll32.exe inetcpl.cpl, Clearmytracksbyprocess 8
//4.form. Data (form data)
RunDll32.exe inetcpl.cpl,clearmytracksbyprocess
//5.passwords (password)
RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess
//6.delete All (delete all)
RunDll32.exe inetcpl.cpl, Clearmytracksbyprocess 255
//7.delete All-"Also Delete files and settings stored by add-ons"
RunDll32.exe Cpl.cpl,clearmytracksbyprocess 4351
< two. ShellExecute
performs the purge function ShellExecute () on the command line above using the call Win32 API function. ShellExecute's function is to run an external program or open a registered file, open a directory, print a file, and so on, and have some control of the external program. Its function prototype and parameters are defined as follows:
The ShellExecute function runs an external program and controls the program (execution returns the application handle successfully) static extern IntPtr ShellExecute (INTPTR hwnd,//For specifying the parent window handle String lpoperation,//To specify the action to be performed. where open filename Specifies the file or folder print print Explore browse (runas edit find) string lpFileName, Used to specify the name of the file to be manipulated or the program file name to execute string lpparameters,//give the specified parameter to the program you want to open. If filename is an executable program, this parameter specifies the command-line arguments. Otherwise the file is open here. The parameter is nil Strin
G lpdirectory,//default directory, used to specify default directory Showcommands nshowcmd//Open options. If the filename parameter is an executable program, this parameter specifies the initial display of the program window, otherwise this parameter is 0; ShellExecute function ShowCmd parameter optional value public enum Showcommands:int {sw_hide = 0,//hidden window and Active State another window (active) sw_show
NORMAL = 1,//display window with original size and position, activate Sw_normal = 1,//Sw_shownormal sw_showminimized = 2,//Minimize window, activate sw_showmaximized = 3,//Maximize window, activate Sw_maximize = 3,//sw_showmaximized sw_shownoactivate = 4,//with nearest size and Position display, do not change active window (not activated) Sw_show = 5,///Sw_shownormal Sw_minimize = 6,//minimized window, inactive sw_showminnoact IVE = 7,//Sw_minimize SW_showna = 8,//Sw_shownoactivate Sw_restore = 9,//with sw_shownormal Sw_showdefault = 10,//Same sw_ Shownormal sw_forceminimize = 11,//Minimized window Sw_max = 11//Same SW_SHOWNORMAL}
invokes the Win32 API ( These APIs are the program interfaces provided by Microsoft ) by [DllImport ("Shell32.dll")]. Before you can invoke the class library in the form of an API declaration. Shell32.dll this system file is an important file that is stored in the Windows System folder and is typically created during installation of the operating system. The program source code is as follows:
//shellexecute function showcmd parameter optional value public enum Showcommands:int {sw_hide = 0, SW_SHOWNORMAL = 1,
Sw_normal = 1, sw_showminimized = 2, sw_showmaximized = 3, sw_maximize = 3, sw_shownoactivate = 4, Sw_show = 5, sw_minimize = 6, sw_showminnoactive = 7, Sw_showna = 8, Sw_restore = 9, Sw_showdefault = Sw_forceminimize = Sw_max = 11}//Calling Win32 API [DllImport ("Shell32.dll")] static extern IntPtr shellexec
Ute (INTPTR hwnd, String lpoperation, String lpfile, String lpparameters, String lpdirectory, Showcommands nshowcmd); Click Button1 to delete the IE temporary file private void Button1_Click (object sender, EventArgs e) {ShellExecute (IntPtr.Zero, "open", "Rundl L32.exe "," inetcpl.cpl,clearmytracksbyprocess 255 "," ", showcommands.sw_showmaximized);}
where DllImport needs to refer to the named control using System.Runtime.InteropServices, and it RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 255 Delete all files. The INTPTR structure is used to represent a pointer or handle-specific type IntPtr.Zero a handle initialized to zero. The results of the operation are shown in the following illustration:
Note: Although learning the specific use of ShellExecute, but still about the showcommands parameters do not understand its specific changes, and the relevant aspects of the books are too few, I hope that you provide some books and better methods.
< three. ShellExecute feature Extension
The ShellExecute () function also uses a lot of functions to bring convenience to everyone, here are a few simple usages. (Replace the above button1 code)
Call Rundll32.exe Purge history
ShellExecute (IntPtr.Zero, "open", "rundll32.exe",
"Inetcpl.cpl, Clearmytracksbyprocess 255 "," ", showcommands.sw_showmaximized);
Visit the csdn eastmount blog
ShellExecute (this. Handle, "open", "Http://blog.csdn.net/eastmount",
null, NULL, showcommands.sw_show);
Send mail
ShellExecute (this. Handle, "open", "mailto:eastmount@163.com",
null, NULL, showcommands.sw_show);
Call Calc.exe to open the calculator
ShellExecute (this. Handle, "open", "calc.exe", NULL, NULL, showcommands.sw_forceminimize);
Call NOTEPAD.EXE to open Notepad
ShellExecute (this. Handle, "open", "Notepad." EXE ", NULL, NULL, showcommands.sw_shownormal);
< four. Call Process start RunDll32.exe
using Rundll32,exe to run the Internet option implementation to delete a temporary file can also invoke the process initiation RunDll32.exe implementation. The following code is for reference only, I did not study the method, only as an online note for myself to view:
Clear IE cache, cookies, and all records
private void Ieclear ()
{
Process process = new process ();
Process. Startinfo.filename = "RunDll32.exe";
Process. startinfo.arguments = "Inetcpl.cpl,clearmytracksbyprocess 255";
Process. Startinfo.useshellexecute = false; Closes the shell's use
process. Startinfo.redirectstandardinput = true; REDIRECT standard input
process. Startinfo.redirectstandardoutput = true; Redirects the standard output
process. Startinfo.redirectstandarderror = true; Redirects the error output
process. Startinfo.createnowindow = true;
Process. Start ();
}
Four. Summary
This article mainly combined with its own project to clear the browser cookies, ie temporary files, recent history, the article is very good to show my mind:
1. First the author thought of getting the corresponding path to the specified file, You can implement this feature by emptying the file under the path;
2. However, because the system files can not be accessed or stopped, so the author found the use of RunDll32.exe implementation, mainly about calling Win32 API function ShellExecute Delete IE cache;
3. Finally, the functions and other operations of the Shellexcute () function are supplemented, and the code that invokes the process initiation RunDll32.exe.
At the same time, the author describes the use of recent history articles, cookies, and sessions for Windows in a series of articles, and finally completes the article to implement the Purge history operation (other methods are the same).
Article quotes Baidu Encyclopedia C # to clear IE Temporary file cache cookies Method |xueer8835 Articles | ZJW articles | adam Viki articles | CSDN Delete Cookies to discuss Thank these authors, and also hope that you can learn through the link.
finally hope that the article for everyone to help, if there are errors or deficiencies, please Haihan!
(By:eastmount 2014-1-28 night 1 http://blog.csdn.net/eastmount )