Re: Impossible to get the sysuptime on windows 2000
On Sun, 16 Mar 2008 14:03:16 -0700, Tim Roberts <timr@probo.com> wrote:
Norbert Unterberg <nunterberg@newsgroups.nospam> wrote:
Tim Roberts schrieb:
You may be overthinking this. If all you need is the system up time,
GetTickCount returns that in milliseconds, accurate to roughly 20
milliseconds of resolution.
Not for computers that ar running for more than 49.7 days. Then it wraps around.
One could also use QueryPerformanceCounter() and QueryPerformanceFrequency().
The count divided by the frequency gives seconds and is good for a lot longer
than the tick count.
There are other options ... timestamps on pagefile.sys, timestamps on many of
the subkeys of HKLM\System\CurrentControlSet (RegQueryInfoKey()); I find about a
thousand subkeys in there with last-write timestamps equal to startup time
(you'd have to pick one you considered reliable).
Does Win2K have WMI? If so either of this query might do it:
"Select * from Win32_OperatingSystem",LastBootUpTime
I believe Win2K's ntdll.dll has NtQuerySystemInformation(). If I'm correct
about that this should get you started:
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;
// in some function
{
SYSTEM_TIME_INFORMATION Sti;
FILETIME ftSystemBoot, ftSystemNow;;
SYSTEMTIME stSystemBoot;
NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(
GetModuleHandle("ntdll"),
"NtQuerySystemInformation"
);
if ( !NtQuerySystemInformation ||
NtQuerySystemInformation(SystemTimeInformation,&Sti,sizeof(Sti),0) !=
NO_ERROR )
return 1;
ftSystemBoot = *((FILETIME*)&(Sti.liKeBootTime));
FileTimeToLocalFileTime(&ftSystemBoot,&ftSystemBoot);
FileTimeToSystemTime(&ftSystemBoot,&stSystemBoot);
// ...
}
--
- Vince