164

How can I know when my computer running Windows 7 was last restarted?

I prefer a solution that doesn't involve searching the event log, but something like wmic or maybe cmd commands.

slhck
  • 235,242
Royi Namir
  • 5,888

16 Answers16

222

systeminfo command is almost right what you need. On English Windows 7 you can also do:

systeminfo | find /i "Boot Time"

Or with the help of WMIC:

wmic os get lastbootuptime

The main difference between Windows 7 and Windows XP that in Windows 7 Microsoft can show only last boot up time.


Also in Task Manager:

enter image description here

m0nhawk
  • 3,863
37

Another way to do this is to use the following command which I tested successfully on Windows XP, Windows 7 and Windows 10:

net statistics workstation

It is faster than systeminfo while formatting the date (which wmic does not). You can find more informations on the net statistics command here: http://technet.microsoft.com/en-us/library/bb490714.aspx

Here is an example of the result:

example

More details on http://en.wikipedia.org/wiki/Uptime about the accuracy when determining system uptime.

Additional notes from the comments: this method determines when the workstation service was last started, not the computer uptime. While this should in general be the same, the 2 numbers might be different if you use sleep/hibernate.

dan
  • 534
20

There's the LastBootUpTime property of the Win32_OperatingSystem class. You can use WMIC with this command:

wmic os get lastbootuptime

Or if you use Powershell, you can convert the time to something more readable than that annoying WMI datetime format:

Get-WmiObject -class Win32_OperatingSystem | Select-Object  __SERVER,@{label='LastBootUpTime';expression={$_.ConvertToDateTime($_.LastBootUpTime)}}

Note that in later versions of PowerShell, you can also use Get-CimInstance, which will automatically return the value as a datetime:

Get-CimInstance -Class Win32_OperatingSystem | Select-Object LastBootUpTime

The only irritating thing is that Get-CimInstance will sometimes change the name of some system fields from WMI objects, such as __SERVER here. You'd have to use either CSName or PSComputerName, which seems to work for me.

Chin
  • 8,013
Bacon Bits
  • 6,665
13

For Windows 10 users out there....

System Properties Windows 10 - Performance Up time

user
  • 30,336
8

Please note that as pointed out by Alex the /sleepstudy command wasn't added until Windows 8.1. /systempowerreport might work instead.

Note that some of these other answers never worked for me, like searching the event-log for example was always missing some entries. @Florisz's answer is also correct in that regard. Here is my solution:

In an administrator cmd shell, run the following command:

powercfg /sleepstudy /output sleepstudy.html

Then open the file sleepstudy.html in a browser. You will be greeted with amazingly organized statistics about shutdown/reboot/standby/hibernation from the last three days. (so, run periodically if you need)

An example of an output: (AFAIR, Showdown (Hybrid) means fast startup)

enter image description here

Source / Documentation | Also related

confetti
  • 2,605
4

Note most of these answers will give the last "restart" time as requested by the OP. But some of you who shutdown your computer rather than restart it will notice that the time doesn't match your boot time.

To get the true last start time, open a PowerShell command prompt (doesn't need to be run as an administrator):

Get-WinEvent -ProviderName Microsoft-Windows-Kernel-boot -MaxEvents 10 | Where-Object {$_.id -eq "27"}

Which will return:

ProviderName: Microsoft-Windows-Kernel-Boot

TimeCreated Id LevelDisplayName Message


3/6/2021 1:00:00 PM 27 Information The boot type was 0x1.

In the Message field you'll see one of these boot types:

Boot             Type Description
0x0              cold boot from full shutdown
0x1              hybrid boot (fast startup)
0x2              resume from hibernation

Counterintuitively, after a restart the boot type will be 0x0 but after a shutdown (with Fast Start) the boot type will be 0x1.

You can isolate the time value with:

Get-WinEvent -ProviderName Microsoft-Windows-Kernel-boot -MaxEvents 10 | Where-Object {$_.id -eq "27"} | select -ExpandProperty TimeCreated

Saturday, March 6, 2021 1:00:00 PM

The reason systeminfo | find "Boot Time" and other similar solutions give the last restart time rather than the time you booted Windows after a shutdown has to do with "Fast Startup" which is on by default (read more here: https://www.howtogeek.com/349114/shutting-down-doesnt-fully-shut-down-windows-10-but-restarting-it-does/).

I've always considered an explicit shut down to be a more thorough way of restarting a computer but in fact that seems to be incorrect under Windows 10 with Fast Startup enabled. However, you can force a "hard" shutdown even with Fast Startup enabled by holding down the shift key while clicking "Shut Down" from the start menu.

User
  • 3,835
3

On just about any version of windows you can check the timestamp on the swap file.

dir /a:h c:\pagefile.sys

Chuck
  • 151
3

You can use PowerShell for this.

Shutdown


Get-WinEvent -LogName Microsoft-Windows-Diagnostics-Performance/Operational | Where { $_.Id -eq 200 }

This will give you a list of logged shutdown times.

Alternative command, better optimized for remote connections:

Get-WinEvent -FilterHashtable @{LogName = "Microsoft-Windows-Diagnostics-Performance/Operational"; Id = 200; }

Example output:

TimeCreated                     Id LevelDisplayName Message
-----------                     -- ---------------- -------
2017-01-28 18:25:46            200 Critical         Windows has shutdown
2016-11-01 19:55:21            200 Error            Windows has shutdown
2016-10-29 00:18:38            200 Critical         Windows has shutdown
2016-10-26 23:16:55            200 Warning          Windows has shutdown
2016-10-26 15:37:40            200 Warning          Windows has shutdown
2016-10-26 02:18:24            200 Warning          Windows has shutdown
2016-10-26 02:10:34            200 Warning          Windows has shutdown
2016-10-26 02:04:01            200 Warning          Windows has shutdown
2016-10-25 14:23:11            200 Warning          Windows has shutdown
2016-10-25 13:07:46            200 Error            Windows has shutdown
2016-10-25 00:18:12            200 Error            Windows has shutdown
2016-10-19 13:16:39            200 Critical         Windows has shutdown

Startup


The following command will give you a list of logged startup times.

Get-WinEvent -LogName Microsoft-Windows-Diagnostics-Performance/Operational | Where { $_.Id -eq 100}

Alternative command, better optimized for remote connections:

Get-WinEvent -FilterHashtable @{LogName = "Microsoft-Windows-Diagnostics-Performance/Operational"; Id = 100; }

Example output:

TimeCreated                     Id LevelDisplayName Message
-----------                     -- ---------------- -------
2017-10-07 21:35:38            100 Critical         Windows has started up
2017-01-28 18:25:48            100 Critical         Windows has started up
2016-12-11 17:45:07            100 Critical         Windows has started up
2016-11-16 13:26:52            100 Critical         Windows has started up
2016-11-01 19:55:21            100 Critical         Windows has started up
2016-10-29 00:18:39            100 Critical         Windows has started up
2016-10-26 23:16:55            100 Error            Windows has started up
2016-10-26 14:51:07            100 Error            Windows has started up
2016-10-26 02:24:01            100 Error            Windows has started up
2016-10-26 02:18:24            100 Critical         Windows has started up
2016-10-26 02:10:34            100 Error            Windows has started up
2016-10-26 02:04:01            100 Critical         Windows has started up
2016-10-25 14:23:12            100 Error            Windows has started up
2016-10-25 13:07:47            100 Error            Windows has started up
2016-10-25 12:56:23            100 Error            Windows has started up
2016-10-19 13:16:39            100 Critical         Windows has started up

I have tested this on PowerShell 5.1 and Windows 10.0.15063. But it should work on Windows 7 as well, as long as you have at least PowerShell 3.0. Note that you need to run it as admin.

You will find the full documentation for the command here: docs.microsoft.com

Samir
  • 21,235
3

To get it in PowerShell:

Function Get-LastBoot {
        if ($Host.Version.Major -lt 3) {
            Get-WmiObject win32_operatingsystem | Select-Object CSname, @{n = 'LastBootUpTime'; e = {$_.ConverttoDateTime($_.lastbootuptime)}}
        }
        else {
            Get-CimInstance -ClassName win32_operatingsystem | Select-Object CSname, LastBootUpTime
        }
    }

Here's the result:

CSname  LastBootUpTime
------  --------------
LAPTOP1 2018-09-07 08:57:02
PollusB
  • 130
2

yet another way in a batch file to get boot time with wmic but in human readable form :

for /f %%a in ('WMIC OS GET lastbootuptime ^| find "."') DO set DTS=%%a
set BOOTTIME=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%  %DTS:~8,2%:%DTS:~10,2%
echo DTS      : %DTS%
echo BOOTTIME :%BOOTTIME%

output :

DTS : 20170308073729.491206+060

BOOTTIME : 2017-03-08 07:37

Max
  • 141
2

From a similar ServerFault question, search/filter the Windows System Event Log for Event ID 6009.

On Windows 10: Event Viewer > Windows Logs > System and then the Filter Current Log... Action.

palswim
  • 3,601
2

A couple of answers mentions net statistics workstation and I've noted that both :

net statistics server

and

net statistics workstation

should provide data regarding last boot on the Statistics since ... line.

However, some OS versions (like Svr2008/6.0) will return 1/1/1980 12:00 for the date when using server. So I'll default to workstation.

Also you can abbreviate some of the command like net stats workstation and get the same results. Finally, if you jump around from system to system, the default CMD box isn't large enough to show all results from the command. So I'll pipe the output to more to avoid scrolling up to see the boot time. Therefore, my default command is:

net stats workstation | more

command

C0deDaedalus
  • 2,730
ictm
  • 21
2

On Windows 7 I prefer

net statistics workstation

WMIC doesn't take into account sleep time, and I leave my workstation locked up at work sleeping during the week, ready to wake up the next day.

tbc0
  • 319
1

I want to add, that all these commands really give you the timestamps when a 'restart' or 'reboot' is done. And not when a shutdown and start is done. After shutdown and start the 'lastbootuptime' will reflect the time the system is really 'restarted' and not the actual boot up time. So shutdown/start gives the same result as coming back from suspend/hybernnate for the LastBootUpTime timestamp.

1

You can use Get-Uptime in PowerShell 6.0 or greater, or if you install PowerShell Community Extensions (Pscx) module if you're on PowerShell 5.1

Output looks like this from Pscx 3.3.2
Pscx does not have the -since option

Get-Uptime

Uptime LastBootUpTime


11.01:20:06.7927825 11/08/2023 12:45:12 PM

Jason S
  • 199
  • 1
  • 7
0

Same as Max answer ...

for /f %%a in ('WMIC OS GET lastbootuptime ^| find "."') DO set DTS=%%a
set BOOTTIME=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%  %DTS:~8,2%:%DTS:~10,2%
echo DTS      : %DTS%
echo BOOTTIME :%BOOTTIME%

...but in oneliner:

for /f %a in ('WMIC OS GET lastbootuptime ^| find "."') DO set DTS=%a && echo %DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2% %DTS:~8,2%:%DTS:~10,2%

This wmi implementation may appear a little messy but it's very fast compared to other powershell or systeminfo implementations and you can easily change the format since it's explicit in the code.

Thank you Max.

Loïc
  • 1