返回列表 发帖

[转帖]Windows 2000系统中如何获取系统的启动时间

// timeboot.cpp (Windows NT/2000) // // This example will show how you can get the time // when your system was booted. // // (c)1999 Ashot Oganesyan K, SmartLine, Inc // mailto:ashot@aha.ru, http://www.protect-me.com, http://www.codepile.com #include #include #define SystemTimeInformation 3 typedef struct _SYSTEM_TIME_INFORMATION { LARGE_INTEGER liKeBootTime; LARGE_INTEGER liKeSystemTime; LARGE_INTEGER liExpTimeZoneBias; ULONG uCurrentTimeZoneId; DWORD dwReserved; } SYSTEM_TIME_INFORMATION; // ntdll!NtQuerySystemInformation (NT specific!) // // The function copies the system information of the // specified type into a buffer // // NTSYSAPI // NTSTATUS // NTAPI // NtQuerySystemInformation( // IN UINT SystemInformationClass, // information type // OUT PVOID SystemInformation, // pointer to buffer // IN ULONG SystemInformationLength, // buffer size in bytes // OUT PULONG ReturnLength OPTIONAL // pointer to a 32-bit // // variable that receives // // the number of bytes // // written to the buffer // ); typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG); PROCNTQSI NtQuerySystemInformation; void main(void) { SYSTEM_TIME_INFORMATION Sti; LONG status; FILETIME ftSystemBoot; SYSTEMTIME stSystemBoot; NtQuerySystemInformation = (PROCNTQSI)GetProcAddress( GetModuleHandle("ntdll"), "NtQuerySystemInformation" ); if (!NtQuerySystemInformation) return; status = NtQuerySystemInformation(SystemTimeInformation,&Sti,sizeof(Sti),0); if (status!=NO_ERROR) return; ftSystemBoot = *(FILETIME *)&(Sti.liKeBootTime); FileTimeToLocalFileTime(&ftSystemBoot,&ftSystemBoot); FileTimeToSystemTime(&ftSystemBoot,&stSystemBoot); printf("Date: %02d-%02d-%04d\nTime: %02d:%02d:%02d\n", stSystemBoot.wMonth,stSystemBoot.wDay,stSystemBoot.wYear, stSystemBoot.wHour,stSystemBoot.wMinute,stSystemBoot.wSecond); }

返回列表 回复 发帖