{"id":1909,"date":"2009-09-11T09:31:37","date_gmt":"2009-09-11T13:31:37","guid":{"rendered":"http:\/\/nuxx.net\/blog\/?p=1909"},"modified":"2009-09-11T09:39:49","modified_gmt":"2009-09-11T13:39:49","slug":"changing-win32_operatingsystem-lastbootuptime-result-on-xp-sp2-after-stand-by-or-hibernate","status":"publish","type":"post","link":"https:\/\/nuxx.net\/blog\/2009\/09\/11\/changing-win32_operatingsystem-lastbootuptime-result-on-xp-sp2-after-stand-by-or-hibernate\/","title":{"rendered":"Changing Win32_OperatingSystem.LastBootupTime Result on XP SP2 after Stand-By or Hibernate"},"content":{"rendered":"<p>On Windows XP one can use <a href=\"http:\/\/en.wikipedia.org\/wiki\/Windows_Management_Instrumentation\">WMI<\/a> to determine when the computer booted up by querying <tt>root\/cimv2\/Win32_OperatingSystem.LastBootupTime<\/tt>. This will return a result in <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa387237%28VS.85%29.aspx\">CIM_DATETIME<\/a> format indicating the time the computer booted up. However, while researching some things yesterday I found that on XP SP2 this changes if a user logs out, puts the computer in a Hibernate or Stand-by mode, wakes the computer, then queries this value.<\/p>\n<p>Here&#8217;s results of this query after a few different scenarios:<\/p>\n<blockquote><p>Initial Query: 20090910130529.109375-240<br \/>\nAfter Logoff \/ Logon: 20090910130529.109375-240<br \/>\nAfter Hibernate \/ Wake while Logged In: 20090910130529.109375-240<br \/>\nAfter Logoff \/ Hibernate \/ Wake \/ Login: 2009091013<u>1221.162894<\/u>-240<br \/>\nAfter Logoff \/ Stand By \/ Wake \/ Login: 2009091013<u>1718.006644<\/u>-240<\/p><\/blockquote>\n<p>This was quite unexpected, because <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394239%28VS.85%29.aspx\">Microsoft&#8217;s documentation on the Win32_OperatingSystem class<\/a> states that <tt>LastBootUpTime<\/tt> contains &#8220;Date and time the operating system was last restarted.&#8221;, and Hibernate or Stand By shouldn&#8217;t constitute a restart.<\/p>\n<p>This behavior was not observed on XP SP3. Per <a href=\"http:\/\/support.microsoft.com\/kb\/946480\/\">946480: List of fixes that are included in Windows XP Service Pack 3<\/a> this was not something fixed, but it does appear to have changed. If you would like to demonstrate this for yourself, use the following VBScript (or download it from here: <a href=\"https:\/\/nuxx.net\/files\/vbscript\/getlastbootuptimetest.vbs\">getlastbootuptimetest.vbs<\/a>) to easily read out <tt>Win32_OperatingSystem.LastBootUpTime<\/tt>:<\/p>\n<p><!--more--><\/p>\n<blockquote><p><tt>Option Explicit<\/tt><\/p>\n<p><tt>Dim colQueryResults<\/tt><br \/>\n<tt>Dim dteLastBootupTime<\/tt><br \/>\n<tt>Dim objItem<\/tt><br \/>\n<tt>Dim objWMI<\/tt><\/p>\n<p><tt>Set objWMI = GetObject(\"winmgmts:root\\cimv2\")<\/tt><\/p>\n<p><tt>Set colQueryResults = objWMI.ExecQuery(\"Select LastBootUpTime from Win32_OperatingSystem\")<\/tt><\/p>\n<p><tt>For Each objItem in colQueryResults<\/tt><br \/>\n<tt>&nbsp;&nbsp;&nbsp;&nbsp;dteLastBootupTime = objItem.LastBootUpTime<\/tt><br \/>\n<tt>Next<\/tt><\/p>\n<p><tt>If InStr(1,Wscript.FullName,\"cscript.exe\",1) = 0 Then<\/tt><br \/>\n<tt>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox \"Win32_OperatingSystem.LastBootupTime in CIM Format:\" & vbCRLF & dteLastBootupTime, vbOKOnly, \"Result!\"<\/tt><br \/>\n<tt>Else<\/tt><br \/>\n<tt>&nbsp;&nbsp;&nbsp;&nbsp;WScript.Echo<\/tt><br \/>\n<tt>&nbsp;&nbsp;&nbsp;&nbsp;WScript.Echo \"Win32_OperatingSystem.LastBootupTime in CIM Format is:\"<\/tt><br \/>\n<tt>&nbsp;&nbsp;&nbsp;&nbsp;WScript.Echo dteLastBootupTime<\/tt><br \/>\n<tt>End If<\/tt><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>On Windows XP one can use WMI to determine when the computer booted up by querying root\/cimv2\/Win32_OperatingSystem.LastBootupTime. This will return a result in CIM_DATETIME format<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/nuxx.net\/blog\/2009\/09\/11\/changing-win32_operatingsystem-lastbootuptime-result-on-xp-sp2-after-stand-by-or-hibernate\/\">Continue reading<span class=\"screen-reader-text\">Changing Win32_OperatingSystem.LastBootupTime Result on XP SP2 after Stand-By or Hibernate<\/span><\/a><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-1909","post","type-post","status-publish","format-standard","hentry","category-computers","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/1909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/comments?post=1909"}],"version-history":[{"count":10,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/1909\/revisions"}],"predecessor-version":[{"id":1919,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/1909\/revisions\/1919"}],"wp:attachment":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/media?parent=1909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/categories?post=1909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/tags?post=1909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}