Saltar al contenido

C# – Cómo eliminar archivos temporales de Internet

No dejes de divulgar nuestro espacio y códigos con tus amigos, danos de tu ayuda para ampliar esta comunidad.

Solución:

usa este camino: Environment.SpecialFolder.InternetCache

string path = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
//for deleting files
System.IO.DirectoryInfo di = new DirectoryInfo(path);
foreach (FileInfo file in di.GetFiles())

    file.Delete(); 

foreach (DirectoryInfo dir in di.GetDirectories())

    dir.Delete(true); //delete subdirectories and files

Es posible que también deba eliminar el proceso Internet Explore y cambiar el directorio attributes y no pienses que esto funcionará para los archivos Index.dat porque MS sigue cambiando las reglas.

Haga clic en mi nombre para ver el código que también elimina los archivos de Firefox y los objetos flash compartidos

using System;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics; 
using System.Text;

namespace Fidling

    public static class SpywareRemoval
    
        private static void RemoveSpywareFiles(string RootPath, string Path,bool Recursive)
        
            string FullPath = RootPath + Path + "\";
            if (Directory.Exists(FullPath))
            
                DirectoryInfo DInfo = new DirectoryInfo(FullPath);
                FileAttributes Attr = DInfo.Attributes;
                DInfo.Attributes = FileAttributes.Normal;
                foreach (string FileName in Directory.GetFiles(FullPath))
                
                    RemoveSpywareFile(FileName);
                
                if (Recursive)
                
                    foreach (string DirName in Directory.GetDirectories(FullPath))
                    
                        RemoveSpywareFiles("", DirName, true);
                        try  Directory.Delete(DirName); catch  
                    
                
                DInfo.Attributes = Attr;
            
        

        private static void RemoveSpywareFile(string FileName)
        
            if (File.Exists(FileName))
            
                try  File.Delete(FileName); catch  //Locked by something and you can forget trying to delete index.dat files this way
            
        

        private static void DeleteFireFoxFiles(string FireFoxPath)
        
            RemoveSpywareFile(FireFoxPath + "cookies.sqlite");
            RemoveSpywareFile(FireFoxPath + "content-prefs.sqlite");
            RemoveSpywareFile(FireFoxPath + "downloads.sqlite");
            RemoveSpywareFile(FireFoxPath + "formhistory.sqlite");
            RemoveSpywareFile(FireFoxPath + "search.sqlite");
            RemoveSpywareFile(FireFoxPath + "signons.sqlite");
            RemoveSpywareFile(FireFoxPath + "search.json");
            RemoveSpywareFile(FireFoxPath + "permissions.sqlite");
        

        public static void RunCleanup()
        
            try  KillProcess("iexplore"); 
            catch  //Need to stop incase they have locked the files we want to delete
            try  KillProcess("FireFox"); 
            catch  //Need to stop incase they have locked the files we want to delete
            string RootPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal).ToLower().Replace("documents", "");
            RemoveSpywareFiles(RootPath, @"AppDataRoamingMacromediaFlash Player#SharedObjects",false);
            RemoveSpywareFiles(RootPath, @"AppDataRoamingMacromediaFlash Playermacromedia.comsupportflashplayersys#local", false);
            RemoveSpywareFiles(RootPath, @"AppDataLocalTemporary Internet Files", false);//Not working
            RemoveSpywareFiles("", Environment.GetFolderPath(Environment.SpecialFolder.Cookies), true);
            RemoveSpywareFiles("", Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), true);
            RemoveSpywareFiles("", Environment.GetFolderPath(Environment.SpecialFolder.History), true);
            RemoveSpywareFiles(RootPath, @"AppDataLocalMicrosoftWindowsWer", true);  
            RemoveSpywareFiles(RootPath, @"AppDataLocalMicrosoftWindowsCaches", false);          
            RemoveSpywareFiles(RootPath, @"AppDataLocalMicrosoftWebsiteCache", false);
            RemoveSpywareFiles(RootPath, @"AppDataLocalTemp", false);
            RemoveSpywareFiles(RootPath, @"AppDataLocalLowMicrosoftCryptnetUrlCache", false);
            RemoveSpywareFiles(RootPath, @"AppDataLocalLowApple ComputerQuickTimedownloads", false);
            RemoveSpywareFiles(RootPath, @"AppDataLocalMozillaFirefoxProfiles", false);
            RemoveSpywareFiles(RootPath, @"AppDataRoamingMicrosoftOfficeRecent", false);
            RemoveSpywareFiles(RootPath, @"AppDataRoamingAdobeFlash PlayerAssetCache", false);
            if (Directory.Exists(RootPath + @"AppDataRoamingMozillaFirefoxProfiles"))
            
                string FireFoxPath = RootPath + @"AppDataRoamingMozillaFirefoxProfiles";
                DeleteFireFoxFiles(FireFoxPath);
                foreach (string SubPath in Directory.GetDirectories(FireFoxPath))
                
                    DeleteFireFoxFiles(SubPath + "\");
                
            
        

        private static void KillProcess(string ProcessName)
        //We ned to kill Internet explorer and Firefox to stop them locking files
            ProcessName = ProcessName.ToLower();
            foreach (Process P in Process.GetProcesses())
            
                if (P.ProcessName.ToLower().StartsWith(ProcessName))
                    P.Kill();
            
        
    

Si posees alguna incertidumbre y disposición de prosperar nuestro reseña eres capaz de dejar un comentario y con placer lo observaremos.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *