背景:
阅读新闻

How to Clear INetCache in C#

  作者: 今日评论: [字体: ]

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();

来源:
录入日期:[2018/03/17 3:01:00]
收藏 推荐 打印 | 录入:mikebai | 阅读:
文章评论      
正在加载评论列表...
评论表单加载中...