码迷,mamicode.com
首页 > 其他好文 > 详细

获取开机时间

时间:2014-08-13 14:54:46      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   for   ar   art   时间   amp   

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">1、用当前时间减去从开机到现在经过了的时间:</span>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></span><pre name="code" class="cpp">	DWORD dwStartTicks = GetTickCount() / 1000 / 60;	// 分钟

	SYSTEMTIME sysTime;
	GetSystemTime(&sysTime);

	FILETIME fileTime;
	ULARGE_INTEGER ulTime;
	SystemTimeToFileTime(&sysTime, &fileTime);
	ulTime.HighPart = fileTime.dwHighDateTime;
	ulTime.LowPart = fileTime.dwLowDateTime;

	DWORD dwCurTime = ulTime.QuadPart / (10 * 1000 * 1000 * 60);	// 分钟


这种方法不太精确。

2、利用未公开的系统函数 NtQuerySystemInformation:

此函数在NTDLL.DLL中导出。

	typedef struct
	{
		LARGE_INTEGER liKeBootTime;
		LARGE_INTEGER liKeSystemTime;
		LARGE_INTEGER liExpTimeZoneBias;
		ULONG uCurrentTimeZoneId;
		DWORD dwReserved;
	} SYSTEM_TIME_INFORMATION; 

	LONG status;
	SYSTEM_TIME_INFORMATION Sti;

	HMODULE hMod = LoadLibraryW(L"NTDLL.DLL");
	if(hMod)
	{
		typedef HRESULT (__stdcall * PFNtQuerySystemInformation)(IN UINT SystemInformationClass,OUT PVOID SystemInformation,IN ULONG SystemInformationLength, OUT PULONG ReturnLength OPTIONAL);

		PFNtQuerySystemInformation pfnNtQuerySystemInformation = (PFNtQuerySystemInformation)GetProcAddress(hMod, "NtQuerySystemInformation");

		if(pfnNtQuerySystemInformation)
			pfnNtQuerySystemInformation(3, &Sti, sizeof(Sti), 0);

		FreeLibrary(hMod);
	}
	DWORD dwCurTime = Sti.liKeBootTime.QuadPart / (1000 * 60); // 分钟

获取开机时间,布布扣,bubuko.com

获取开机时间

标签:style   color   io   for   ar   art   时间   amp   

原文地址:http://blog.csdn.net/lisl812/article/details/38536657

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!