从注册表项中检索LastWrite时间 [英] Retrieving the LastWrite time from a Registry key

查看:350
本文介绍了从注册表项中检索LastWrite时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试从存储USB安装的设备信息的注册表项中检索LastWrite时间,而在转换为DateTime时遇到问题.

我正在使用 RegQueryInfoKey [

Hi,

I am trying to retrieve the LastWrite time from the Registry key that stores USB mounted device information and I''m having problems with the conversion to DateTime.

I am using the RegQueryInfoKey[^] API and my code to retireve a DateTime object is:

 // override RegQueryInfoKey. lpftLastWriteTime represented by int array
queryInfoKey = RegQueryInfoKey(hSubKey, null, null, IntPtr.Zero,
                ref lpcSubKeys, null, null, ref lpcValues, null, null, null, lpftLastWriteTime);
// subtract the high datetime form the low datetime. low datetime is negative
long lastWriteTime = (((long)lpftLastWriteTime[1]) << 32) + (long)lpftLastWriteTime[0];
                
// convert long to DateTime object
DateTime lastWrite = DateTime.FromFileTime(lastWriteTime);



但是,此代码在每种情况下都不会返回正确的LastWrite时间.

有人可以对此有所了解吗?

谢谢


Shockmeister.



However, this code does not return the correct LastWrite time in every case.

Can someone shed a bit of light on this?

Thanks


Shockmeister.

推荐答案

仅回答我自己的问题:-D,问题在于FILETIME结构的定义. Win32结构使用DWORD成员(未签名),而.NET Framework类型使用SIGNED整数.

请参阅本文以获取更多信息:thumbsup:

http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7! 146.entry?sa = 683367813 [ ^ ]


我很惊讶以前没有人遇到过这个问题!
Just to answer my own question :-D , the problem lies with the definition of the FILETIME structure. The Win32 structure uses DWORD members, which are UNSIGNED, whereas the .NET Framework type uses SIGNED ints.

See this article for more information :thumbsup:

http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!146.entry?sa=683367813[^]


I''m suprised no one has come across this problem before!


这篇关于从注册表项中检索LastWrite时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆