🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #16133

Re: Get the system uptime?

#16133
From: Vladimir Afanasyev
Date: Wed, 28 May 2003 14:18
89 lines
3215 bytes
For XP but not tested:

void __fastcall TForm1::Button2Click(TObject *Sender)
{
typedef WINBASEAPI
BOOL
WINAPI (*GetSystemTimes)
(LPFILETIME,LPFILETIME,LPFILETIME);

FILETIME IdleTime, KernelTime, UserTime;
LARGE_INTEGER it,kt,ut;

GetSystemTimes GST;
HMODULE Mod=GetModuleHandle("kernel32.dll");
if(Mod == NULL)
        {
         ShowMessage("kernel32.dll is not mapped");
         Application->Terminate();
         return;
        }
GST=(GetSystemTimes)GetProcAddress(Mod,"GetSystemTimes");
if(!GST)
        {
         ShowMessage("GetSystemTimes is absent");
         Application->Terminate();
         return;
        }

BOOL res=GST(&IdleTime, &KernelTime, &UserTime);


if(res)
 {
it.LowPart=IdleTime.dwLowDateTime;
it.HighPart=IdleTime.dwHighDateTime;
Edit1->Text=IntToStr(it.QuadPart);

kt.LowPart=KernelTime.dwLowDateTime;
kt.HighPart=KernelTime.dwHighDateTime;
Edit2->Text=IntToStr(kt.QuadPart);

ut.LowPart=UserTime.dwLowDateTime;
ut.HighPart=UserTime.dwHighDateTime;
Edit3->Text=IntToStr(ut.QuadPart);

 }

}


For Win2000 and XP but internal Windows function:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
typedef struct
_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION {
    LARGE_INTEGER IdleTime;
    LARGE_INTEGER KernelTime;
    LARGE_INTEGER UserTime;
    LARGE_INTEGER Reserved1[2];
    ULONG Reserved2;
} SYSTEM_PROCESSOR_PERFORMANCE;
DWORD dl;

SYSTEM_PROCESSOR_PERFORMANCE spr;

typedef WINBASEAPI
DWORD
WINAPI (*NtQuerySystemInformation)(int, PVOID, ULONG, PULONG);

NtQuerySystemInformation NtQuerySystemInformationFunc;

HMODULE Mod=GetModuleHandle("ntdll.dll");
if(Mod == NULL)
        {
         ShowMessage("ntdll.dll is not mapped");
         Application->Terminate();
         return;
        }
NtQuerySystemInformationFunc=(NtQuerySystemInformation)GetProcAddress(Mod,"NtQuerySystemInformation");
BOOL res=NtQuerySystemInformationFunc(8, &spr, sizeof(SYSTEM_PROCESSOR_PERFORMANCE),&dl);
Edit7->Text=IntToStr(spr.IdleTime.QuadPart);
Edit8->Text=IntToStr(spr.KernelTime.QuadPart);
Edit9->Text=IntToStr(spr.UserTime.QuadPart);
}


Vladimir.
Technical Details
Message-ID: <3ed4c534$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!pln-w!extra.newsguy.com!lotsanews.com!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3ed3dfa5$1@newsgroups.borland.com> <3ed47392$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,7346dca14e776e6d
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-05-28 07:29:33 PST
From: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Subject: Re: Get the system uptime?
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 62.244.14.114 62.244.14.114    
X-Forwarded-For: 192.168.0.147
References:  <3ed3dfa5$1@newsgroups.borland.com> <3ed47392$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3ed4c534$1@newsgroups.borland.com>
Date: 28 May 2003 07:18:28 -0700
X-Trace: newsgroups.borland.com 1054131508 207.105.83.65 (28 May 2003 07:18:28 -0700)
Lines: 90
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!pln-w!extra.newsguy.com!lotsanews.com!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail