windows kernel 时间

时间:2020-10-08 18:19:30   收藏:0   阅读:30

获取系统时间

  LARGE_INTEGER system_time = { 0 };
  LARGE_INTEGER local_time = { 0 };
  TIME_FIELDS local_time_fields = { 0 };

  KeQuerySystemTime(&system_time);
  ExSystemTimeToLocalTime(&system_time, &local_time);
  RtlTimeToTimeFields(&local_time, &local_time_fields);

  DbgPrintEx(0, 0, "%4d-%2d-%2d %2d:%2d:%2d\n", 
    local_time_fields.Year, local_time_fields.Month, local_time_fields.Day,
    local_time_fields.Hour, local_time_fields.Minute, local_time_fields.Second);

暂停线程

#define DELAY_ONE_MICROSEC (-10) // 负值表示相对时间
#define DELAY_ONE_MILLISEC (DELAY_ONE_MICROSEC*1000)

  LARGE_INTEGER interval = { 0 };
  interval.QuadPart = 2 * 1000 * DELAY_ONE_MILLISEC;
  KeDelayExecutionThread(KernelMode, FALSE, &interval);
  DbgPrintEx(0, 0, "hello..\n"); // 暂停2s后打印
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!