Click here to Skip to main content
13,352,157 members (73,619 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


16 bookmarked
Posted 12 Feb 2008

How to Get the Last Restart/Reboot Time for Windows

, 12 Feb 2008
Rate this:
Please Sign up or sign in to vote.
This code snippet helps to get the last Windows reboot time using C# and interop


This code snippet helps to get the time when the Windows OS was last rebooted, using C# code.


It was required for me to get the last restart time for Windows in my program. But unfortunately I couldn't find any direct APIs from .NET. Also some articles suggested using the NetStat command and parsing the output as the available solution.

Using the Code

The following code snippet in C# will be helpful in getting the last restart time for Windows.

IntPtr bufPtr = IntPtr.Zero;
int val = NetStatisticsGet(null, "LanmanWorkstation", 0, 0, out bufPtr);
if (val == 0)
    wks = (STAT_WORKSTATION_0)Marshal.PtrToStructure(bufPtr, typeof(STAT_WORKSTATION_0));
DateTime aRebootTime = DateTime.FromFileTime(wks.StatisticsStartTime);

Points of Interest

The current code shows how to get the last restart time for the workstation. It is also possible get the restart time from the server.


  • 12th February, 2008: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Gautham Jayaraman
Software Developer Working for an MNC
India India
Working for an MNC for last 5 years. Currently in application development, mainly ASP.NET. Has also worked with internet security and penetration testing. MCSD .NET certified. Enjoys travelling and food.

You may also be interested in...

Comments and Discussions

GeneralLast Reboot Time Pin
Member 39685012-Jan-09 7:41
memberMember 39685012-Jan-09 7:41 
QuestionCan you explain how it works? Pin
adaiye19-Feb-08 21:14
memberadaiye19-Feb-08 21:14 
GeneralAnother way... Pin
VDJ18-Feb-08 23:31
memberVDJ18-Feb-08 23:31 
GeneralSystem.Environment.TickCount Pin
Member 206208818-Feb-08 17:56
memberMember 206208818-Feb-08 17:56 
GeneralRe: System.Environment.TickCount Pin
Predrag Tomasevic23-Nov-11 13:09
memberPredrag Tomasevic23-Nov-11 13:09 
Dunno who down-voted this... it's probably the best way.
GeneralSecurity Event Log Pin
PeterTheGreat12-Feb-08 5:40
memberPeterTheGreat12-Feb-08 5:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 12 Feb 2008
Article Copyright 2008 by Gautham Jayaraman
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid