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