Summary C # Two ways to clear the cookies for the IE temporary file cache

Source: Internet
Author: User
Tags win32

Like what:
Temporary Internet Files (Temporary Internet file)
RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 8

Cookies
RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 2

History (historical records)
RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 1

Form. Data (Form information)
RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 16

Passwords (password)
RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 32

Delete all (remove all)
RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 255

Delete all-"Also deletes files and settings stored by add-ons"
RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 4351

How do we invoke these instructions in C # programming? There are 2 ways to invoke process initiation RunDll32.exe, and the second is to invoke the Win32 API function ShellExecute or CreateProcess to execute the above command line.

Method One: Invoke process start RunDll32.exe

private void Ieclear ()
{
Clear IE cache, cookies, and all records
Process process = new process ();
Process. Startinfo.filename = "RunDll32.exe";
Process. startinfo.arguments = "Inetcpl.cpl,clearmytracksbyprocess 255";
Process. Startinfo.useshellexecute = false;
Process. Startinfo.redirectstandardinput = true;
Process. Startinfo.redirectstandardoutput = true;
Process. Startinfo.redirectstandarderror = true;
Process. Startinfo.createnowindow = true;
Process. Start ();
}

Method Two: Call Win32 API function ShellExecute or CreateProcess to execute the above command line is OK.

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
}

[DllImport ("Shell32.dll")]
static extern IntPtr ShellExecute (IntPtr hwnd, String lpoperation, String lpfile, String lpparameters, String lpdirectory , Showcommands nShowCmd);

Clear IE Temp file
ShellExecute (IntPtr.Zero, "open", "rundll32.exe", "Inetcpl.cpl,clearmytracksbyprocess 8", "", showcommands.sw_hide);

Through the above methods can be successfully deleted in the software IE cookies, caching, temporary files and so on.

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.