我读取IE缓存文件后,怎么copy  IE缓存中的文件,一般的copy方法好像不行,得不到文件流。请问该怎么办,windows有没有提供什么接口,谢谢

解决方案 »

  1.   

    使用
    GetUrlCacheEntryInfo,前提是你要知道文件的url.
    MSDN:
    http://msdn.microsoft.com/en-us/library/aa384185(VS.85).aspx一个帖子:
    Accessing IE cache in C#
    http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/622dd0b5-c100-4330-bdc7-db78a7757d72一篇文章:阐述了为什么你得不到文件流
    http://blog.datalisto.com/2008/08/accessing-contents-of-ie-cache.html
      

  2.   

    我自己解决了这个问题,顺便提示一下:
    我启动了一个进程,调用了winscp脚本,基本思路等于在DOS下操作了文件。以此,我也发现了WINDOWS的一些安全隐患问题,windows的安全性仅仅针对于在WMINDOWS平台下,由于windows是在DOS的基础上开发起来的,所以无法超越DOS的权限。由此如果用winscp开发一些病毒,会相当方便,也会相当隐蔽。再次澄清,不对上述言论承担任何责任仅供学习交流。
      

  3.   

    我在用C#写一个IE缓存提取器,现在最大的也是唯一的问题就是无法从IE缓存里面复制出文件。
      

  4.   

    IE缓存提取器我早做完了,由于以前一直在51CTO上泡,所以没来得及回复。现把我的源码贴上:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    //using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Text.RegularExpressions;
    using System.IO;
    using Microsoft.Win32;namespace IE缓存提取器
    {
        public partial class Form1 : Form
        {
            string IEPath = ""; //定义变量保存IE缓存路径
            string FileKind = ""; //定义选取的文件类型        public Form1()
            {
                InitializeComponent();
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。
                this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。
                this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中显示。
            }        private void button3_Click(object sender, EventArgs e)
            {
                MessageBox.Show("本软件由南京农业大学绿岛网络开发协会陆健(陆少Tonycup)开发。");
            }        private void button4_Click(object sender, EventArgs e)
            {
                this.Close();
            }        private void button5_Click(object sender, EventArgs e)
            {
                SelectFolder.ShowDialog();
                SavetBox.Text = SelectFolder.SelectedPath;
            }        private void DelButton_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("确认清除IE缓存?", "Confirm Message", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
                    foreach (FileInfo info in dir.GetFiles("*.*", SearchOption.AllDirectories))
                    {
                        try
                        {
                            info.Delete();
                        }
                        catch
                        {
                            continue;
                        }
                    }
                    MessageBox.Show("清除成功!");
                }        }        private void DoButton_Click(object sender, EventArgs e)
            {           
                FileKind = KindcBox.Text; //获取要提取的文件类型
                string SavePath = SavetBox.Text; //获取文件保存路径            if (FileKind == "" || SavePath == "")
                {
                    MessageBox.Show("请检查文本框是否为空!", "提示", MessageBoxButtons.OK);
                }
                else
                {
                    //label6.Text = "处理进度:";
                    //progressBar1.Maximum = 100; //进行进度条操作
                    progressBar1.Show();   //显示进度条
                    progressBar1.Value = 50;                DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));//获取IE缓存目录
                    DoPath pp = new DoPath();                pp.Copy(dir.ToString(), SavePath, FileKind); //调用方法                //label6.Text = "处理完成!";
                    progressBar1.Value = 100; //其实进度条操作是假的,只是一个样子,避免文件过多,用户不耐烦
                    if (MessageBox.Show("提取成功!是否打开这个文件夹?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        progressBar1.Hide();
                        System.Diagnostics.Process.Start(SavePath);
                    }
                    //label6.Text = "";
                    else{
                    progressBar1.Hide(); //提取完,隐藏进度条
                    }
                }
            }        private void Form1_Load(object sender, EventArgs e)
            {
                //progressBar1.Hide();  //窗体加载时隐藏进度条
                DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
                IEPath = dir.ToString();
            }        private void button1_Click_1(object sender, EventArgs e)
            {
                SavetBox.Text = "";
                KindcBox.Text = "";
            }        private void button6_Click(object sender, EventArgs e)
            {
                //打开IE缓存目录
                base.OnLoad(e);
                DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
                System.Diagnostics.Process.Start(dir.FullName);  //进程 处理
            }        private void button2_Click(object sender, EventArgs e)
            {
                System.Diagnostics.Process.Start("http://www.lvdaonet.cn/");  //链接到我们绿岛网络首页
            }    }    public class DoPath  
        {
            public string iePath = "";        public void Copy(string sourceDirectory, string targetDirectory,string FileKind)
            {
            DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
            DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);        CopySome(diSource, diTarget,FileKind);
            }
            public static void CopySome(DirectoryInfo source, DirectoryInfo target,string FileKind) //这个方法用来Copy缓存里面的文件的
            {
                // 检查文件夹是否存在,不在就创建它,下面三段基本上都是从MSDN复制过来的,发现MSDN太好用了!!!
                if (Directory.Exists(target.FullName) == false)
                {
                    Directory.CreateDirectory(target.FullName);
                }            // 复制选中的文件
                foreach (FileInfo fi in source.GetFiles(FileKind, SearchOption.AllDirectories))
                {
                    Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name);
                    fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
                }            // 每个子目录中使用递归复制
                foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
                {
                    DirectoryInfo nextTargetSubDir =
                        target.CreateSubdirectory(diSourceSubDir.Name);
                    CopySome(diSourceSubDir, nextTargetSubDir,FileKind);
                }
            }        public string getPath()//原本是用这个方法(从注册表里面读取IE缓存路径)来获取IE缓存路径的,现在发现有更好的办法,只要一句话,从环境变量中就可以获取了,所以这个方法就没有用了
                //新代码是:DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
            {
                //获取IE路径
                RegistryKey regRead;
                //读取子键
                regRead = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache\\Paths\\path1", true);
                if (regRead == null) //如果该子键不存在
                {
                    MessageBox.Show("No Data!");
                }
                else
                {
                    object obj = regRead.GetValue("CachePath");  //读取CachePath项的值
                    iePath = obj.ToString();       //写进iePath
                    iePath = iePath.Replace("\\Content.IE5\\Cache1",""); //把后面的多余的去掉            }
                //关闭该对象
                regRead.Close();
                return iePath;  //返回路径
            }
        }
    }