Q> Как узнать время старта системы (uptime) ?

A> (c)1999 Ashot Oganesyan K, SmartLine, Inc mailto:ashot@aha.ru

// timeboot.cpp (Windows NT/2000)

#include <windows.h>
#include <stdio.h>

#define SystemTimeInformation 3

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

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);
}


Рейтинг@Mail.ru be number one Submitter.ru - Promoting!
Хостинг от uCoz