Find out if the computer has rebooted since the last time I started my program?

How can my program know if Windows has rebooted since its last launch? All versions of Windows XP and on.

+3
source share
8 answers

This can be done trivially using the global atom table. Just make sure your atom name is unlikely to conflict with another atom.

if (GlobalFindAtom ("MySecretName") == 0) { // First time run since reboot GlobalAddAtom ("MySecretName"); } 
+6
source

There is a Windows API call that you can make with GetTickCount ...

http://msdn.microsoft.com/en-us/library/ms724408%28VS.85%29.aspx

Edit:. The idea is that when you start your program, you call GetTickCount (which returns how many milliseconds Windows is running) and then calculates the exact start date (right now minus the number of milliseconds). Save this date, and then the next time you start the program, calculate the date and compare it with the previously saved date. If the dates are different, Windows rebooted. Use GetTickCount64 if possible (but do not code your solution exclusively with this function.

+3
source

You can use WMI:

  strComputer = "." Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOS in colOperatingSystems dtmBootup = objOS.LastBootUpTime dtmLastBootupTime = WMIDateStringToDate(dtmBootup) dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now) Wscript.Echo dtmSystemUptime Next Function WMIDateStringToDate(dtmBootup) WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _ Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _ & " " & Mid (dtmBootup, 9, 2) & ":" & _ Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _ 13, 2)) End Function 
+1
source
 net statistics workstation|find "Statistics since" 
+1
source

The Microsoft uptime.exe utility "processes the machineโ€™s event log to determine system availability and current uptime."

+1
source

A simple but ugly solution : just run an endless bogus process :-)

If it is still here, you have not rebooted. If this is not the case, most likely you have just rebooted.

0
source

In the spirit of ugly hacks ... paste something into one of RunOnce registry keys

0
source

How to add a file to% TMP% and check if everything is there (% TMP% should be cleaned every time you restart Windows)

or

a more reliable way, create a file somewhere and mark it for deletion at the next reboot (see the MoveFileEx API ) and check that the file

0
source

All Articles