如何删除临时文件、清空cookie、删除历史记录等,最好有现成的代码

解决方案 »

  1.   

    http://www.codeproject.com/KB/vb/trackercleaner.aspx
      

  2.   

    建立一个批处理文件,取名如:ClearTemp.Bat,要清理时运行即可@echo off 
    echo 正在清除系统垃圾文件,请稍等...... 
    del /f /s /q %systemdrive%\*.tmp 
    del /f /s /q %systemdrive%\*._mp 
    del /f /s /q %systemdrive%\*.log 
    del /f /s /q %systemdrive%\*.gid 
    del /f /s /q %systemdrive%\*.chk 
    del /f /s /q %systemdrive%\*.old 
    del /f /s /q %systemdrive%\recycled\*.* 
    del /f /s /q %windir%\*.bak 
    del /f /s /q %windir%\prefetch\*.* 
    rd /s /q %windir%\temp & md %windir%\temp 
    del /f /q %userprofile%\cookies\*.* 
    del /f /q %userprofile%\recent\*.* 
    del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*" 
    del /f /s /q "%userprofile%\Local Settings\Temp\*.*" 
    del /f /s /q "%userprofile%\recent\*.*" 
    echo 清除系统系统垃圾文件完成! 
    echo. & pause  
      

  3.   

    不能直接删除用户计算机中的 Cookie。但是,可以通过将 Cookie 的到期日期设置为过去的日期,让用户的浏览器来删除 Cookie。当用户下一次向设置该 Cookie 的域或路径内的页发出请求时,浏览器将确定该 Cookie 已到期并将其移除。调用 Cookies集合的 Remove方法可从服务器端的集合中移除 Cookie,使 Cookie 不会被发送至客户端。但是,如果客户端已存在 Cookie,则向 Cookie 分配已过去的到期日期1,确定 Cookie 是否存在,如果存在则创建同名的新 Cookie。2,将 Cookie 的到期日期设置为过去的某一时间。3,将 Cookie 添加到 Cookies 集合对象。下面的代码示例演示如何为 Cookie 设置已过去的到期日期。C#
    if (Request.Cookies["UserSettings"] != null)
    {
        HttpCookie myCookie = new HttpCookie("UserSettings");
        myCookie.Expires = DateTime.Now.AddDays(-1d);
        Response.Cookies.Add(myCookie);
    }