内核获得开机嘀嗒数和当前时间

From:windows驱动编程基础教程

#include <ntddk.h>


VOID DriverUnload(IN PDRIVER_OBJECT DriverObject)
{
	DbgPrint("卸载完成!\n");
}




LARGE_INTEGER MyGetTickCount ()
{
	
	//KeQueryTickCount 嘀嗒总数目
	//KeQueryTimeIncrement 1个嘀嗒所需时间
	
	LARGE_INTEGER    tick_count;
	ULONG            inc;

    KeQueryTickCount(&tick_count);//返回“嘀嗒”数,一个“嘀嗒”数的时间不定,要根据硬件,可用KeQueryTimeIncrement查询
	inc = KeQueryTimeIncrement();//返回一个“嘀嗒”数所用时间,inc的单位是100纳秒。1s==10-6 ms
	
	tick_count.QuadPart *= inc;
	tick_count.QuadPart /= 600000000;//转化为分钟



return tick_count;
}




void GetCurrentTime()
{

//KeQuerySystemTime 格林威治标准时间
//ExSystemTimeToLocalTime() 转化为当地时间
//RtlTimeFieldsToTime() 转化为 年 月 日 等人为可观时间
LARGE_INTEGER systemTime;
LARGE_INTEGER localTime;
TIME_FIELDS time;
KeQuerySystemTime (&systemTime);
ExSystemTimeToLocalTime (&systemTime,&localTime);
RtlTimeToTimeFields(&localTime,&time);
DbgPrint("%d年%d月%d日 %d:%d:%d",time.Year,time.Month,time.Day,time.Hour,time.Minute,time.Second);

}



NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)
{
	
	
	KdPrint(("系统已启动 %d 分钟", MyGetTickCount().QuadPart));
    
	GetCurrentTime();


	DriverObject->DriverUnload = DriverUnload;




	return STATUS_SUCCESS;
}


你可能感兴趣的:(内核获得开机嘀嗒数和当前时间)