Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how to get the time of pc before the shutdown !! and thanks!!!

i found this

VB
Private Sub button1_Click(sender As Object, e As EventArgs)
    MessageBox.Show(GetLastSystemShutdown().ToString())
End Sub

Public Shared Function GetLastSystemShutdown() As DateTime
    Dim sKey As String = "System\CurrentControlSet\Control\Windows"
    Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sKey)

    Dim sValueName As String = "ShutdownTime"
    Dim val As Byte() = DirectCast(key.GetValue(sValueName), Byte())
    Dim valueAsLong As Long = BitConverter.ToInt64(val, 0)
    Return DateTime.FromFileTime(valueAsLong)
End Function


but this it's gives you the result after the shutdown !! all what i want is to have the last time before the bigin of shutdown and thanks alot
Posted
Comments
PhilLenoir 22-Aug-14 9:46am    
Have you tried looking at the event logs?
moussafar 22-Aug-14 9:50am    
i tried and i found nothing!!!
Pheonyx 22-Aug-14 11:19am    
I believe you should see events in the event log for a "shutdown/Logoff", however if the computer shuts down because of a power outage or other unexpected event, you will only see a post "unexpected shutdown" event log entry.
moussafar 22-Aug-14 13:40pm    
can you give me an exemple please i'm just a newer in vb.net !! and thanks for answer me !! thanks alot
Sergey Alexandrovich Kryukov 22-Aug-14 15:48pm    
What do you mean "before shutdown"? Strictly speaking, Windows does not know that it's going to shutdown in next moment. Do you mean the moment of time when shutdown is requested? Or something else?
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900