首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 网络编程-> C#/CSHARP教程
用 C# 获取 IE 临时文件-.NET教程,C#语言
作者:网友供稿 点击:16
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
大家知道,在我们访问一个网站的时候。系统会把这个网站上的图片,动画等内容全部缓存到internet临时文件夹中。
我们可以通过 <drives>:\documents and settings\<user>\local settings\temporary internet files访问。但是可能我们都没有想到,里面的文件实际却不同于我们系统中其他的文件夹和文件的关系。

举例说明,我们在vs.net下写一个函数来返回指定文件夹中的文件夹和所有文件时,但我们把internet临时文件夹的地址传进去时,系统只会返回一个文件,那就是desktop.ini(每个文件夹都有),还有一个隐藏的文件夹。所以这就证明了在临时文件夹中的文件并不是按照普通的文件夹与文件的方式存在的。

其实windows是把临时文件全部存在一个隐藏的文件夹中,这个文件夹是我们都看不到的,然后靠一个index.dat的索引把内容全部读出来回显给用户。

那我们怎么用程序来读取其中的内容呢? 因为这几天在帮同学完成他的毕业设计,所以研究了一下。
首先要引用一个user.dll,在系统文件夹中。然后利用它其中的一些函数就可以遍历整个文件夹,并获得其中每个文件的信息。

[dllimport("wininet.dll", setlasterror=true, charset=charset.auto)]
public static extern intptr findfirsturlcacheentry(
[marshalas(unmanagedtype.lptstr)] string lpszurlsearchpattern,
intptr lpfirstcacheentryinfo,
ref int lpdwfirstcacheentryinfobuffersize);

[dllimport("wininet.dll", setlasterror=true, charset=charset.auto)]
public static extern bool findnexturlcacheentry(
intptr henumhandle,
intptr lpnextcacheentryinfo,
ref int lpdwnextcacheentryinfobuffersize);

[dllimport("wininet.dll")]
public static extern bool findcloseurlcache(
intptr henumhandle);


引入以上三个函数来遍历临时文件夹,然后再引用

[dllimport("kernel32.dll",setlasterror=true, charset=charset.auto)]
public static extern int filetimetosystemtime(
intptr lpfiletime,
intptr lpsystemtime);

用来把 filetime时间格式转化成c#中的string类型,以便我们进一步操作。

主体程序如下:

#region 引入dll

[structlayout(layoutkind.sequential, charset=charset.auto)]
public struct internet_cache_entry_info
{
public int dwstructsize;
public intptr lpszsourceurlname;
public intptr lpszlocalfilename;
public int cacheentrytype;
public int dwusecount;
public int dwhitrate;
public int dwsizelow;
public int dwsizehigh;
public filetime lastmodifiedtime;
public filetime expiretime;
public filetime lastaccesstime;
public filetime lastsynctime;
public intptr lpheaderinfo;
public int dwheaderinfosize;
public intptr lpszfileextension;
public int dwexemptdelta;
}

[structlayout(layoutkind.sequential, charset=charset.auto)]
public struct systemtime
{
public short wyear;
public short wmonth;
public short wdayofweek;
public short wday;
public short whour;
public short wminute;
public short wsecond;
public short wmilliseconds;
}

[dllimport("kernel32.dll",setlasterror=true, charset=charset.auto)]
public static extern int filetimetosystemtime(
intptr lpfiletime,
intptr lpsystemtime);

[dllimport("wininet.dll", setlasterror=true, charset=charset.auto)]
public static extern intptr findfirsturlcacheentry(
[marshalas(unmanagedtype.lptstr)] string lpszurlsearchpattern,
intptr lpfirstcacheentryinfo,
ref int lpdwfirstcacheentryinfobuffersize);

[dllimport("wininet.dll", setlasterror=true, charset=charset.auto)]
public static extern bool findnexturlcacheentry(
intptr henumhandle,
intptr lpnextcacheentryinfo,
ref int lpdwnextcacheentryinfobuffersize);

[dllimport("wininet.dll")]
public static extern bool findcloseurlcache(
intptr henumhandle);

const int error_no_more_items = 259;

#endregion

#region filetimetosystemtime

private string filetimetodatatime(filetime time)
{
intptr filetime = marshal.allochglobal( marshal.sizeof(typeof(filetime)) );
intptr systime = marshal.allochglobal( marshal.sizeof(typeof(systemtime)) );
marshal.structuretoptr(time,filetime,true);
filetimetosystemtime( filetime ,systime);
systemtime st = (systemtime) marshal.ptrtostructure(systime,typeof(systemtime));
string time = st.wyear.tostring()+"."+st.wmonth.tostring()+"."+st.wday.tostring()+"."+st.whour.tostring()+"."+st.wminute.tostring()+"."+st.wsecond.tostring();
return time;
}

#endregion

#region 加载数据
private void fileok_click(object sender, system.eventargs e)
{

int nneeded = 0, nbufsize;
intptr buf;
internet_cache_entry_info cacheitem;
intptr henum;
bool r;

findfirsturlcacheentry( null, intptr.zero, ref nneeded );

if ( marshal.getlastwin32error() == error_no_more_items )
return;

nbufsize = nneeded;
buf = marshal.allochglobal( nbufsize );
henum = findfirsturlcacheentry( null, buf, ref nneeded );
while ( true )
{
cacheitem = (internet_cache_entry_info) marshal.ptrtostructure( buf,
typeof(internet_cache_entry_info) );

string modifiedtime = filetimetodatatime(cacheitem.lastmodifiedtime);
string expiretime = filetimetodatatime(cacheitem.expiretime);
string accesstime = filetimetodatatime(cacheitem.lastaccesstime);
string synctime = filetimetodatatime(cacheitem.lastsynctime);

#region 获得数据,存入数据库
try
{

//此處遍歷cacheitem即可
//例如
string s = marshal.ptrtostringauto(cacheitem.lpszsourceurlname);
}
catch
{
//異常處理
}
#endregion

string s = marshal.ptrtostringauto(cacheitem.lpszsourceurlname);

nneeded = nbufsize;
r = findnexturlcacheentry( henum, buf, ref nneeded );

if ( !r && marshal.getlastwin32error() == error_no_more_items )
break;

if ( !r && nneeded > nbufsize )
{
nbufsize = nneeded;
buf = marshal.reallochglobal( buf, (intptr) nbufsize );
findnexturlcacheentry( henum, buf, ref nneeded );
}
}

messagebox.show("系统数据加载完毕!");
marshal.freehglobal( buf );

}

#endregion




文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·使用C#编写Windows Forms应用程序(转)-.NET教程,Windows开发
·C#学习杂记-.NET教程,C#语言
·将文本格式的文章转换为html/xml格式文本的功能封装到Javabean-JSP教程,Java技巧及代码
·用java小程序applet实现无限级树结构-JSP教程,Java技巧及代码
·《.net编程先锋C#》第一章 C#简介-.NET教程,C#语言
·企业人事信息管理系统1.0-ASP教程,数据库相关
·《.net编程先锋C#》第三章 第一个C#应用程序-.NET教程,C#语言
·《.net编程先锋C#》第二章 理论基础-公用语言 运行环境-.NET教程,C#语言
·Windows应用程序调试必备的--符号文件(Symbols)-.NET教程,评论及其它
·c#反编译微软msdn2003的帮助文档,并将反编译结果保存到一个sqlserver数据库中
最新文章
·vista的新特性:懒人的安全感_windows vista
·photoshop为情侣照片打造韩式梦幻相框_photoshop教程
·专访seobbs站长乐思蜀_站长访谈
·嘟嘟网络陈艺光:诚信是一种信仰_站长访谈
·俺自己黄修源:只问耕耘,不问收获_站长访谈
·李向华:如何提高论坛用户粘性_站长访谈
·给windows vista系统网络和共享中心“换脸”_windows vista
·胡宪东谈搜索优化的实战_站长心得
·网站快速成功的九个步骤_站长心得
·google pr数字背后的含意_google推广
相关主题
  • 用 c# 开发 sql server 2005 的自定义聚合函数_c#应用
  • 用 C# 编写一个停放在任务栏上的图标程序-.NET教程,Windows开发
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭