c# delete temporary internet files ignore index.dat

How can you delete temporary internet files and ignore index.dat in c# ?

(this refers to C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\ )

System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 4351");  // Delete All - Also delete files and settings stored by add-ons

parameters that can be used:

Temporary Internet Files
ClearMyTracksByProcess 8

Cookies
ClearMyTracksByProcess 2

History
ClearMyTracksByProcess 1

Form Data
ClearMyTracksByProcess 16

Passwords
ClearMyTracksByProcess 32

Delete All
ClearMyTracksByProcess 255

Delete All – Also delete files and settings stored by add-ons
ClearMyTracksByProcess 4351

4 comments to c# delete temporary internet files ignore index.dat

  • Passing

    Sorry but the above solution does not delete the index.dat files and MS is doing all they can to snoop on you for the CIA.

    You need to kill IExplore and Explorer in win 7 and set both the folder attributes and file attributes to normal before you even try to delete the files from code.

    Not a perfect solution but here is the code in C# and tested on windows 7

    int DeletedCount = 0;
    int CouldNotDelete = 0;
    KillExplorer();
    foreach (string DatFile in DatFiles)
    {//Do not put break point or step into the code else explorer will start and the file will become locked again
    DirectoryInfo DInfo=new DirectoryInfo(DatFile.Replace(“index.dat”,””));
    FileAttributes OldDirAttrib = DInfo.Attributes;
    DInfo.Attributes = FileAttributes.Normal;//Set to normal else can not delete
    FileInfo FInfo = new FileInfo(DatFile);
    FileAttributes OldFileAttrib = FInfo.Attributes;
    SetAttr(FInfo, FileAttributes.Normal);
    TryDelete(FInfo);
    SetAttr(FInfo, OldFileAttrib);//Sets back to Hidden,system,directory,notcontentindexed
    if (File.Exists(DatFile))
    CouldNotDelete++;
    else
    DeletedCount++;

    }
    if (DatFiles.Count>0)//Lets get explorer running again
    System.Diagnostics.Process.Start(DatFiles[DatFiles.Count - 1].Replace(“index.dat”, “”));
    else
    System.Diagnostics.Process.Start(“explorer”);
    System.Windows.Forms.MessageBox.Show(“Deleted ” + DeletedCount + ” Index.dat files with ” + CouldNotDelete + ” Errors”);

    return “Deleted ” + DeleteFileCount + ” Files “;
    }

    private void KillExplorer()
    {
    foreach (Process P in Process.GetProcesses())
    {//Kill both these process because these are the ones locking the files
    if (P.ProcessName.ToLower() == “explorer”)
    P.Kill();
    if (P.ProcessName.ToLower() == “iexplore”)
    P.Kill();
    }
    }

    private bool TryDelete(FileInfo Info)
    {
    try
    {
    Info.Delete();
    return true;
    }
    catch
    {return false;}
    }

    private void SetAttr(FileInfo Info,FileAttributes Attr)
    {
    try
    {
    Info.Attributes = Attr;
    }
    catch { }
    }

  • Microsoft is so desperate to keep you away from Index.dat files that they keeps moving the goalposts via service packs and new versions of windows so what worked yesterday, won’t work today.

    Some of the ‘Special Hidden’ folders won’t show even when you use a registry hack and killing processes ‘Explorer’ and ‘IExplorer’ before you try to delete them still won’t unlock the files on Win 7 X 64 (Build 7600) and running batch files without exposing account names and passwords cannot remove these index.dat files at reboot due to the wrong windows permissions.

    One method that might still works is to boot-up in safe mode and then assign yourself administrator rights and then see if you can find the files to delete or use a batch file to rename the subfolder below the folder containing the index.bat files and to then only copy the folders back to the original location that don’t contain these Spyware files but the resultant batch files needs to be run from a separate windows account that has administrator permissions.

    Click my name to learn more and to view the source code to do the job.

  • Click my name to see source code for deleting most spyware files including Share object/Flash cookies and Firefox sqllite files excluding bookmarks without having to reboot.

    This code does not remove Index.dat files, they are killers to remove

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>