views:

42

answers:

3

Hi,

How do I differentiate in my C++ code between a service coming up as a part of system reboot and service coming up since the user stopped and started the service manually in service manager or using sc tool????

A: 

Using GetTickCount() maybe, to know the time elapsed since system start …

Didier Trosset
Thanks mate :) I was thinking the same . I was trying to run Systeminfo | Find "Up Time" to get the up time, but since I work on embedded XP , System Info was not available
Ganesh
Hey , I checked out GetTickCount, but it has rollback problem, where the value gets rolled back. Is there any other call to query the system up time in windows ??
Ganesh
A: 

If GetTickCount() is unsuitable for your purposes, you could try scanning the System Event Log for the most recent Windows startup event, which has a datetime associated with it...

Jonners
There is a GetSystemInfo() API call in windows ??? Is it possible to get the System up time from this call , since systeminfo also prints System up time???
Ganesh
+1  A: 

Well , there is windows uptime.exe available in Windows NT SP4... or you can download it from MSDN site.. which gives the uptime of the system similar to unix.... Get the output of uptime .... if the call to your Service comes within first 10 mins of the OS boot up , then it starting as result of OS reboot or else its service restart... this is uncomplicated neat heuristic solution.... You also use the cmd systeminfo | Find "Up Time" to get uptime ....

Ganesh