发新话题
打印

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

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

信息来源:邪恶八进制 中国
文章作者:ashot@aha.ru
复制内容到剪贴板
代码:
// 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, [url]http://www.protect-me.com[/url], [url]http://www.codepile.com[/url]

#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;


// 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);
}
请加47809945   100%通过!每个月总有那么几天,您的网络会受到黑客的攻击--坐立不安,烦躁无力,使用虎虎开发的"月月舒"防火墙,超轻超薄,易于携带,提供由内到外的全方位保护,即使流量再大,也可以冲浪自如,再也不用担心侧漏啦。

TOP

发新话题