WDM驱动中如何获得当前系统时间?
可以按照以下步骤:
1. 用 KeQuerySystemTime() 获得当前的 GMT System Time. 这是一个从 1601-01-01 以来的计数(单位是 100ns)。
2. 如果是 Win2000/XP,调用 ExSystemTimeToLocalTime() 将 GMT System Time 值转换成当前时区的 Local System Time.
如果是在 Win9x 下,不能调用 ExSystemTimeToLocalTime(),可以这样作:
查询注册表键 (REG_DWORD)
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/TimeZoneInformation/ActiveTimeBias
得到 Time-Zone Bias 值,再用 GMT System Time 减去 Bias,即可得到 Local System Time。
3. 用 RtlTimeToTimeFields() 将 System Time 值转换成 年:月:日:时:分:秒 的形式,保存在一个 TIME_FIELDS 结构中。
typedef struct TIME_FIELDS
{
CSHORT Year;
CSHORT Month;
CSHORT Day;
CSHORT Hour;
CSHORT Minute;
CSHORT Second;
CSHORT Milliseconds;
CSHORT Weekday;
} TIME_FIELDS;
博客介绍了WDM驱动中获取当前系统时间的步骤。先使用KeQuerySystemTime()获取GMT System Time,接着针对不同系统版本将其转换为Local System Time,Win2000/XP调用ExSystemTimeToLocalTime(),Win9x则通过查询注册表键计算。最后用RtlTimeToTimeFields()将时间值转换为特定格式保存。
3903

被折叠的 条评论
为什么被折叠?



