From: sadanand.sr on
s there any API similar to uptime command in unix which gives the
system boot time?


Thanks & Regards,
Sadanand
From: Dean Earley on
sadanand.sr(a)gmail.com wrote:
> s there any API similar to uptime command in unix which gives the
> system boot time?

GetTickCount is milliseconds since reboot, but it rolls over at 49 and a
bit days.

--
Dean Earley (dean.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems
From: Christian ASTOR on
On 23 juin, 12:18, sadanand...(a)gmail.com wrote:
> Is there any API similar to uptime command in unix which gives the
> system boot time?

Also NtQuerySystemInformation() & SystemTimeOfDayInformation
From: Jerry Coffin on
In article <6e16a7e7-79b6-475c-b05c-40ddd0f4acd8
@g16g2000pri.googlegroups.com>, sadanand.sr(a)gmail.com says...
> s there any API similar to uptime command in unix which gives the
> system boot time?

Not directly, but you can pretty easily create a similar command line
utility. This is the uptime.c I have/use:

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

DWORD FindLsass() {
DWORD process_list[4096];
DWORD module_list[1024];
DWORD process_count, needed;
char filename[1024];

EnumProcesses(process_list,
sizeof(process_list),
&process_count);

for (int i=0; i<process_count; i++) {
EnumProcessModules(process_list[i],
module_list,
sizeof(module_list),
&needed);
GetModuleFileNameEx(process_list[i],
module_list[0],
filename,
sizeof(filename));
if ( strstr(filename, "lsass.exe"))
return process_list[i];
}
}

int main() {
FILETIME creation, exit, kernel, user;
SYSTEMTIME started;

HANDLE winlogon = OpenProcess(PROCESS_QUERY_INFORMATION,
FALSE,
FindLsass());

GetProcessTimes(winlogon,
&creation,
&exit,
&kernel,
&user);

FileTimeToSystemTime(&creation, &started);

printf("System started %d/%d/%d, %d:%2.2d:%2.2d\n",
started.wYear, started.wMonth, started.wDay,
started.wHour, started.wMinute, started.wSecond);

return 0;
}

There's nothing particularly magical about lsass.exe -- it's just one of
a number of processes that's started during system boot, and runs the
whole time the system is running. You could choose any of a few others
such as csrss.exe though, without any major problem. Offhand, I'm not
sure of the exact order in which they start (and I think some of them
are started asynchronously, so the order may be indeterminate). For that
matter, you could argue one way or the other about how close to finished
booting the system has to be before you consider it "up" -- but it's
usually only going to make a few seconds difference at most, and most
people just don't care about that level of precision.

--
Later,
Jerry.

The universe is a figment of its own imagination.
From: Christian ASTOR on
On 23 juin, 13:19, Christian ASTOR <casto...(a)club-internet.fr> wrote:
> On 23 juin, 12:18, sadanand...(a)gmail.com wrote:
>
> > Is there any API similar to uptime command in unix which gives the
> > system boot time?
>
> Also NtQuerySystemInformation() & SystemTimeOfDayInformation

....and SystemUpTime from Win32_PerfRawData_PerfOS_System