Clear temporary internet files via “C#”

2019-02-16 01:24发布

问题:

I am using webbrowser control in windows application.i was viewing url content inside the webbrowser control. here the url content values are stored in temporary internet files of user machine.

when i click close button in my form i was deleting the temporary internet files programatically. and it is working fine. but during deletion a "message box came and saying deleting temporary internet files".

here i dont want to show that dialog box during deletion. below is code to delete the temp files for users machine.

how to handle this..

   void DeleteBrowserTempFile()
    {
        string args = "";
        args = ("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 = args;
        processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        processStartInfo.UseShellExecute = true;
        try
        {
            process = System.Diagnostics.Process.Start(processStartInfo);
        }
        catch (Exception ex)
        {
            Utilities.WriteErrorLog(ex);
        }
        finally
        {
            if (!(process == null))
            {
                process.Dispose();
            }
        }
    }

is there any other way to achieve this.. need ur suggestions with examples

regards

Anbuselvan

回答1:

Try what Microsoft advises: http://support.microsoft.com/kb/326201