取得windows系统开机日期和时间
2012-11-30 17:04
274 查看
很简单,原生态函数NtQuerySystemInformation已经为我们提供了这个功能,
虽然不那么优雅 :)
虽然不那么优雅 :)
#include <stdio.h> #include <stdbool.h> #include <windows.h> #define NT_SUCCESS(x) ((x)>=0) #define SystemTimeInformation 3 typedef struct { LARGE_INTEGER liKeBootTime; LARGE_INTEGER liKeSystemTime; LARGE_INTEGER liExpTimeZoneBias; ULONG uCurrentTimeZoneId; DWORD dwReserved; } SYSTEM_TIME_INFORMATION; typedef long (__stdcall *fnNtQuerySystemInformation)(\ IN UINT SystemInformationClass,\ OUT PVOID SystemInformation,\ IN ULONG SystemInformationLength,\ OUT PULONG ReturnLength OPTIONAL); static fnNtQuerySystemInformation NtQuerySystemInformation = NULL; int main(void) { NtQuerySystemInformation = (fnNtQuerySystemInformation)\ GetProcAddress(LoadLibrary("ntdll.dll"),\ "NtQuerySystemInformation"); if(NtQuerySystemInformation == NULL) { printf("Get NtQuerySystemInformation Addr Failed!\n"); exit(-1); } LONG status; SYSTEM_TIME_INFORMATION sti; status = NtQuerySystemInformation(SystemTimeInformation,\ &sti,sizeof(sti),0); printf("boot time (ms) == %I64X\n",sti.liKeBootTime.QuadPart); /*if(!NT_SUCCESS(status)) { printf("NtQuerySystemInformation Failed!\n"); goto quit; }*/ if(NO_ERROR != status) { printf("NtQuerySystemInformation Failed!\n"); exit(-1); } FILETIME ft; SYSTEMTIME st; memcpy(&ft,&sti.liKeBootTime,sizeof(ft)); FileTimeToLocalFileTime(&ft,&ft); FileTimeToSystemTime(&ft,&st); printf("Date: %02d-%02d-%04d\nTime: %02d:%02d:%02d\n",st.wMonth,st.wDay,st.wYear,\ st.wHour,st.wMinute,st.wSecond); getchar(); return 0; }
相关文章推荐
- 取得windows系统开机日期和时间
- 取得windows系统开机日期和时间
- C语言下取得系统开机运行时间
- Windows 8系统更改日期、时间和数字格式的方法
- asp.net取得系统时间日期的各种形式
- Windows系统设置开机菜单选择超时等待时间的方法
- 关于(windows)下取得系统日期的方法:用于自动备份等
- Windows和Linux下取得系统时间(毫秒级)
- SQL中如何取得系统时间和日期(时间要求返回6位,比如152910;日期要求返回8位,比如20070517)
- 在Windows批处理中获取系统日期、时间戳记
- 如何读取Windows系统事件日志(获得上次关机时间、本次开机时间等)
- 获取系统开机的时间(Windows、Linux)
- Windows 7系统中怎么更改日期、时间和数字格式?解决方法介绍
- 取得系统当前日期和时间
- Ubuntu10.x 下设置默认开机系统为windows及修改系统等待时间
- 通过这样一个方法可以取得两个日期当中的日期数,或者去的多少天以后的时间
- JAVA获取当前系统时间和日期并格式化输出总结
- Android 系统时间日期的获取
- sql得到当前系统时间得 日期部分
- Windows获取当前系统时间函数总结