Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

obtaining the last boot timestamp

Posted on 2003-10-31
5
Medium Priority
?
640 Views
Last Modified: 2013-12-03
The following code will give me the last boot timestamp.  Is there a C API call or registry location where I can get this info?

On Error Resume Next
strComputer = "."
'strComputer = "useaihp348"
'strComputer = "ihp130"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem",,48)
For Each objItem in colItems
    Wscript.Echo "LastBootUpTime: " & objItem.LastBootUpTime Next

0
Comment
Question by:Kalvyn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 375 total points
ID: 9658352
The performance counters offer such information via 'Win32_PerfRawData_PerfOS_System' (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_perfos_system.asp).
0
 
LVL 86

Expert Comment

by:jkr
ID: 9687582
Any feedback?
0
 

Author Comment

by:Kalvyn
ID: 9690474
Using normal counter logic to get the last boot timestamp would be a very complicated way of getting this information.  Plus the current PDH methods for processing counter information is not available on some pre W2K OS levels.  However, this reply did help me track a related way of getting this information.  I changed my search criteria from "last boot" to "up time" per the counter documentation.  This lead me to the QueryPerformanceCounter and QueryPerformanceFrequency calls for getting this counter information via API calls.

So I would give him some points for the help.  BTW, my current code is as follows.


void GetLastBoot()
{
// This procedure:
// -Calculates system up time.  Note that this is not exactly the same as //  reported by SrvInfo but it is within a few seconds. // -Calculates last boot date/time.  Note that if there was an odd number of //  daylight savings time switches since the last boot date, this will be //  one hour off.
  char temp[256];
  long uptime;
  time_t seconds;
  struct tm *local;
  LARGE_INTEGER PerformanceCount;
  LARGE_INTEGER Frequency;

  if (QueryPerformanceCounter(&PerformanceCount))
  {
    if (QueryPerformanceFrequency(&Frequency))
    {
      time(&seconds);
      uptime= PerformanceCount.QuadPart/Frequency.QuadPart;
      seconds= seconds- uptime;
      local= localtime(&seconds);
      sprintf(temp,"%02i/%02i/%04i %02i:%02i:%02i",
                   local->tm_mon+1,
                   local->tm_mday,
                   local->tm_year +1900,
                   local->tm_hour,
                   local->tm_min,
                   local->tm_sec);
      cout << "  LastBoot=" << temp << endl;
      cout << "  SystemUpTime=";
      cout << (uptime/86400) << " Days ";
      cout << (uptime%86400)/3600 << " Hr ";
      cout << ((uptime%86400)%3600)/60 << " Min ";
      cout << uptime%60 << " Sec" << endl;
    }
    else
      cout << "  Error getting last boot (QueryPerformanceFrequency): " <<
GetLastError() << endl;
  }
  else
    cout << "  Error getting last boot (QueryPerformanceCounter): " <<
GetLastError() << endl;
} // end GetLastBoot
0
 

Author Comment

by:Kalvyn
ID: 9690482
jkr, since your reply pointed my college in the right direction i am awarding the points for your response.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9690494
I actually had the uptime in my mind :o)
Thank you!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question