http://blog.csdn.net/Eastmount/article/details/18821221
This article is mainly about the project "software for the use of records of personal computers" in the article about clearing browser cookies, ie temporary files, recent usage history and so on. The basic idea line of this article is to first understand the internet history of the common file path in Windows. The file Delete method deletes the contents of the file, but many files cannot be read, and the final solution is to remove the cache function with the help of RunDll32.exe's Internet implementation.
An. IE history file path
Internet Explorer has the specified folder store to log all information, including IE cache files, cookies files, recent browsing history, visited URLs, address bar URLs and IE forms/Password records, temporary files, etc. before talking about deleting IE caches, First, the file path of cookies, temporary Internet files, ie history is briefly introduced.
The cookie in 1.Windows is saved as "C:\Users\dell\AppData\Roaming\Microsoft\Windows\Cookies". Cookies record information such as user ID, password, browser pages, dwell time, and so on. As shown in:
The Temporary Internet file location in 2.Windows is "C:\Users\dell\AppData\Local\Microsoft\Windows\Temporary Internet Files", It stores the content of recently viewed Web pages (web | images | media copies, etc.) to quickly query and improve speed later.
The IE history location in 3.Windows is "C:\Users\dell\AppData\Local\Microsoft\Windows\History", and the history is the address of the Web site that was visited in the most recent time, which is stored as time and site. As shown in:
IE usually clears the history also includes: Download history, form data, password, ActiveX and other data, such as:
Two. Delete with file delete
get temporary Internet files file (Environment.SpecialFolder.InternetCache) via Environment.getfolderpath ( Internet temp file) and get the. dat file path in it.
[CSharp]View Plaincopy
- Get the IE temp 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 the. 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);
- }
- }
- }
Reference namespace using System.IO at the same time; the run result is as follows:
In this way, it appears that emptying all files in this folder will enable the removal of temporary Internet files, but using File.delete (FileName) to delete files in the folder will encounter "the file is in use in another process, so the process cannot access this file" or "file access is denied" Because the temporary Internet files directory is a system folder, some files are not read.
(This resource about IE temporary file get view Delete, for everyone to learn http://download.csdn.net/detail/jee89731/3465688)
Three. Call Rundll32.exe implementation
Use RunDll32.exe to run Internet Options corresponding DLL files, to clear IE cache (Temporary Internet files, Cookies, browser history, form records, user name passwords, etc.).
< a >.rundll32.exe
The role of Rundll32.exe (running a 32-bit DLL file) is to execute an intrinsic function in the DLL file and invoke the dynamic-link library from the command line using the command line: Rundll32.exe Dllname,functionname [ Arguments]. (where dllname is required to execute DLL file names, functionname is the specific reference function that executes DLL files, [Arguments] is the specific parameter of the extraction function).
The CTRL+R call runs the input command execution and can run the appropriate action. The Rundll32.exe shell32.dll,Control_RunDLL function is to execute the Display control Panel. Among the things about clearing IE cache operations are as follows:
[CSharp]View Plaincopy
- 1.History (History)
- RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 1
- 2.Cookies
- RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 2
- 3.Temporary Internet Files (Temporary Internet file)
- RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 8
- 4.Form. Data (form)
- RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 16
- 5.Passwords (password)
- RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 32
- 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 inetcpl.cpl,clearmytracksbyprocess 4351
< two;. ShellExecute
Use the Call Win32 API function ShellExecute () to execute the above command line to implement the purge 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 over the external program. Its function prototypes and parameters are defined as follows:
[CSharp]View Plaincopy
- 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 take. Where open opens filename specifies a 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 name of the program file to execute
- string lpparameters, //To specify parameters for the program to open. If filename is an executable program, this parameter specifies a command-line argument. Otherwise open the file here the parameter is nil
- string lpdirectory, //default directory for specifying the default directory
- Showcommands nshowcmd //Open option. If the filename parameter is an executable program, this parameter specifies how the program window is initially displayed, otherwise this parameter is 0
- );
- ShellExecute function ShowCmd Parameter optional value
- Public enum Showcommands: int
- {
- Sw_hide = 0, //Hide window and Active State another window (active)
- Sw_shownormal = 1, //Display the window with its original size and position, activate
- Sw_normal = 1, //with Sw_shownormal
- sw_showminimized = 2, //Minimized window, active
- sw_showmaximized = 3, //Maximize window, activate
- Sw_maximize = 3, //with sw_showmaximized
- Sw_shownoactivate = 4, //display with the nearest size and position, do not change the active window (inactive)
- Sw_show = 5, //with Sw_shownormal
- Sw_minimize = 6, //Minimized window, inactive
- Sw_showminnoactive = 7, //with Sw_minimize
- Sw_showna = 8, //with Sw_shownoactivate
- Sw_restore = 9, //with Sw_shownormal
- Sw_showdefault = ten, //with Sw_shownormal
- Sw_forceminimize = one, //Minimized window
- Sw_max = one //same sw_shownormal
- }
Invoke the Win32 API via [DllImport ("Shell32.dll")] ( These APIs are the program interfaces provided by Microsoft ), The class library in which the API declaration form is called can be invoked after the import. Shell32.dll the system files are important files that are stored in Windows system folders and are typically created during the installation of the operating system. The program source code is as follows:
[CSharp]View Plaincopy
- <span style="FONT-SIZE:14PX;" >//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 = 10,
- Sw_forceminimize = 11,
- Sw_max = 11
- }
- Calling the Win32 API
- [DllImport ("Shell32.dll")]
- Static extern IntPtr ShellExecute (IntPtr hwnd, string lpoperation, string lpfile,
- string lpparameters, string lpdirectory, Showcommands nshowcmd);
- Click Button1 to delete ie temp file
- Private void button1_click (object sender, EventArgs e)
- {
- ShellExecute (IntPtr.Zero, "open", "rundll32.exe",
- "Inetcpl.cpl,clearmytracksbyprocess 255", "" , showcommands.sw_showmaximized);
- }</span>
Where DllImport needs to reference 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 result of the operation is as follows:
Note: Although learning the specific use of ShellExecute, but still about the Showcommands parameter does not understand its specific changes, and the relevant aspects of the book is too few, I hope you can provide some of this book and better methods.
< three;. ShellExecute Feature Extensions
The ShellExecute () function also uses a lot of functions to bring convenience to everyone, here are a few simple usages. (Replace the button1 code above)
[CSharp]View Plaincopy
- Call Rundll32.exe Purge History
- ShellExecute (IntPtr.Zero, "open", "rundll32.exe",
- "Inetcpl.cpl,clearmytracksbyprocess 255", "" , showcommands.sw_showmaximized);
- Visit Csdn Eastmount Blog
- ShellExecute (This. Handle, "open", "Http://blog.csdn.net/eastmount",
- NULL, null, showcommands.sw_show);
- Send mail
- ShellExecute (This. Handle, "open", "Mailto:[email protected]",
- 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
Deleting temporary files with the Rundll32,exe run Internet option can also invoke the process launch RunDll32.exe implementation. The code below is for informational purposes only and I did not study the method as an online note for my own viewing:
[CSharp]View Plaincopy
- 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; //Turn off the use of the shell
- Process. Startinfo.redirectstandardinput = true; //redirect standard input
- Process. Startinfo.redirectstandardoutput = true; //redirect standard output
- Process. Startinfo.redirectstandarderror = true; //redirect error output
- Process. Startinfo.createnowindow = true;
- Process. Start ();
- }
Four. Summary
The article mainly combined with their own projects to clear the browser's cookies, ie temporary files, recent history, the article is very good to show my thoughts:
1. First, the author thought of obtaining the corresponding path of the specified file, empty the file under the path to achieve this function;
2. However, because the system files can not be accessed or stopped, so the author found the use of RunDll32.exe implementation, mainly on the call Win32 API function ShellExecute Delete IE cache;
3. Finally, the function and other operations of the Shellexcute () function are supplemented, and the code that invokes process startup RunDll32.exe is added.
At the same time, the author describes the use of Windows recent history articles, cookies, and sessions in a series of articles, and finally completes this article to implement the Purge history operation (the other way around).
Article cited the Baidu Encyclopedia C # Removal of IE temporary file cache cookies Method |xueer8835 Article | ZJW's Articles | Adam Viki's article | CSDN Delete the cookie discussion thanks to these authors, and also hope that you can learn through the link.
Finally hope that the article is helpful to everyone, if there are errors or shortcomings, please everyone Haihan!
(By:eastmount 2014-1-28 night 1 o ' http://blog.csdn.net/eastmount)
C # System Application of the removal of cookies, ie temporary files, historical records reproduced