mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. DotNET
  3. Main content

How to Clear INetCache in C#

2018-03-17 162hotness 0likes 0comments

How to Clear INetCache in C#

Step 01. Create Variable

private const int INTERNET_OPTION_END_BROWSER_SESSION = 42;

[DllImport("wininet.dll", SetLastError = true)] private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);

Step 02. Create Method

private static void ClearIEFolder()

{

    try

    {

        string args1 = "";

        args1 = ("InetCpl.cpl,ClearMyTracksByProcess 8");

        System.Diagnostics.Process process = null;

        System.Diagnostics.ProcessStartInfo processStartInfo;

        processStartInfo = new System.Diagnostics.ProcessStartInfo();

        processStartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\Rundll32.exe";

        if ((System.Environment.OSVersion.Version.Major >= 6))

        {

            //  Windows Vista or higher

            processStartInfo.Verb = "runas";

        }

        processStartInfo.Arguments = args1;

        processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

        processStartInfo.UseShellExecute = false;

        processStartInfo.RedirectStandardOutput = true;

        processStartInfo.RedirectStandardError = true;

        try

        {

            process = System.Diagnostics.Process.Start(processStartInfo);

        }

        catch { }

        finally

        {

            if (!(process == null))

            {

                process.Dispose();

            }

        }

    }

    catch { }

    try

        {

            InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);

        }

    catch { }

}

Step 03. Call Method

ClearIEFolder();

Tag: Nothing
Last updated:2018-03-17

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang