C # System Application of the removal of cookies, ie temporary files, historical records reproduced

Source: Internet
Author: User
Tags print print

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
  1. Get the IE temp file
  2. Private void button2_click (object sender, EventArgs e)
  3. {
  4. ListBox1.Items.Clear ();
  5. string dirpath = Environment.getfolderpath (Environment.SpecialFolder.InternetCache);
  6. This.textBox1.Text = dirpath.tostring ();
  7. DirectoryInfo dir = new DirectoryInfo (Dirpath);
  8. //Traverse all folders to display the. dat files
  9. foreach (FileInfo file in dir. GetFiles ("*.jpg", searchoption.alldirectories))
  10. {
  11. Try
  12. {
  13. LISTBOX1.ITEMS.ADD (file.  DirectoryName + "\ \" + file);
  14. //file.  Delete ();
  15. }
  16. catch (Exception msg) //exception handling
  17. {
  18. MessageBox.Show (Msg. Message);
  19. }
  20. }
  21. }

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. 1.History (History)
  2. RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 1
  3. 2.Cookies
  4. RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 2
  5. 3.Temporary Internet Files (Temporary Internet file)
  6. RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 8
  7. 4.Form. Data (form)
  8. RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 16
  9. 5.Passwords (password)
  10. RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 32
  11. 6.Delete All (delete all)
  12. RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 255
  13. 7.Delete All-"Also Delete files and settings stored by add-ons"
  14. 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
  1. The ShellExecute function runs an external program and controls the program (execution returns the application handle successfully)
  2. Static extern IntPtr ShellExecute (
  3. INTPTR hwnd, //For specifying the parent window handle
  4. string lpoperation, //To specify the action to take. Where open opens filename specifies a file or folder print print Explore browse (runas edit find)
  5. string lpFileName, //used to specify the name of the file to be manipulated or the name of the program file to execute
  6. 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
  7. string lpdirectory, //default directory for specifying the default directory
  8. 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
  9. );
  10. ShellExecute function ShowCmd Parameter optional value
  11. Public enum Showcommands: int
  12. {
  13. Sw_hide = 0, //Hide window and Active State another window (active)
  14. Sw_shownormal = 1, //Display the window with its original size and position, activate
  15. Sw_normal = 1, //with Sw_shownormal
  16. sw_showminimized = 2, //Minimized window, active
  17. sw_showmaximized = 3, //Maximize window, activate
  18. Sw_maximize = 3, //with sw_showmaximized
  19. Sw_shownoactivate = 4, //display with the nearest size and position, do not change the active window (inactive)
  20. Sw_show = 5, //with Sw_shownormal
  21. Sw_minimize = 6, //Minimized window, inactive
  22. Sw_showminnoactive = 7, //with Sw_minimize
  23. Sw_showna = 8, //with Sw_shownoactivate
  24. Sw_restore = 9, //with Sw_shownormal
  25. Sw_showdefault = ten, //with Sw_shownormal
  26. Sw_forceminimize = one, //Minimized window
  27. Sw_max = one //same sw_shownormal
  28. }

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
  1. <span style="FONT-SIZE:14PX;" >//shellexecute function showcmd parameter optional value
  2. Public enum Showcommands: int
  3. {
  4. Sw_hide = 0,
  5. Sw_shownormal = 1,
  6. Sw_normal = 1,
  7. sw_showminimized = 2,
  8. sw_showmaximized = 3,
  9. Sw_maximize = 3,
  10. Sw_shownoactivate = 4,
  11. Sw_show = 5,
  12. Sw_minimize = 6,
  13. Sw_showminnoactive = 7,
  14. Sw_showna = 8,
  15. Sw_restore = 9,
  16. Sw_showdefault = 10,
  17. Sw_forceminimize = 11,
  18. Sw_max = 11
  19. }
  20. Calling the Win32 API
  21. [DllImport ("Shell32.dll")]
  22. Static extern IntPtr ShellExecute (IntPtr hwnd, string lpoperation, string lpfile,
  23. string lpparameters, string lpdirectory, Showcommands nshowcmd);
  24. Click Button1 to delete ie temp file
  25. Private void button1_click (object sender, EventArgs e)
  26. {
  27. ShellExecute (IntPtr.Zero, "open", "rundll32.exe",
  28. "Inetcpl.cpl,clearmytracksbyprocess 255", "" , showcommands.sw_showmaximized);
  29. }</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
  1. Call Rundll32.exe Purge History
  2. ShellExecute (IntPtr.Zero, "open", "rundll32.exe",
  3. "Inetcpl.cpl,clearmytracksbyprocess 255", "" , showcommands.sw_showmaximized);
  4. Visit Csdn Eastmount Blog
  5. ShellExecute (This. Handle, "open", "Http://blog.csdn.net/eastmount",
  6. NULL, null, showcommands.sw_show);
  7. Send mail
  8. ShellExecute (This. Handle, "open", "Mailto:[email protected]",
  9. NULL, null, showcommands.sw_show);
  10. Call Calc.exe to open the calculator
  11. ShellExecute (This.  Handle, "open", "calc.exe", null, null, showcommands.sw_forceminimize);
  12. Call NOTEPAD.EXE to open Notepad
  13. 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
  1. Clear IE cache, cookies, and all records
  2. Private void Ieclear ()
  3. {
  4. Process Process = new process ();
  5. Process.  Startinfo.filename = "RunDll32.exe";
  6. Process.  startinfo.arguments = "Inetcpl.cpl,clearmytracksbyprocess 255";
  7. Process.        Startinfo.useshellexecute = false; //Turn off the use of the shell
  8. Process.   Startinfo.redirectstandardinput = true; //redirect standard input
  9. Process.  Startinfo.redirectstandardoutput = true; //redirect standard output
  10. Process.   Startinfo.redirectstandarderror = true; //redirect error output
  11. Process.  Startinfo.createnowindow = true;
  12. Process. Start ();
  13. }
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.