Reputation: 1
I am creating a windows application there i need to find exact reason for system shutdown.How can i track that a computer is shut off by power cutoff?? Is there any variable in system environment which tells us how system got shutdown??
Upvotes: 0
Views: 344
Reputation: 18320
Here's a small example of locating all the Kernel Power
events which has the BugCheckCode
set to 0
:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim EventLogInstance As New EventLog("System") 'Open the "System" event log.
For Each Entry As EventLogEntry In EventLogInstance.Entries 'Iterate through all entries.
If GetEventID(Entry.InstanceId) = 41 AndAlso _
(Entry.ReplacementStrings(0) = "0" OrElse Entry.ReplacementStrings(0).Length = 0) Then 'Checks if the "BugCheckCode" is set to 0.
'If GetEventID() returns 41 then we know that the entry is of type "Kernel Power".
ListView1.Items.Add(New ListViewItem(New String() {Entry.TimeGenerated.ToString("yyyy\/MM\/dd hh:mm:ss"), Entry.Message})) 'Add the entry's date, time and error message to a ListView.
End If
Next
ListView1.Sort() 'Sort the listview (here, sorting order is set to Descending).
End Sub
Private Function GetEventID(ByVal InstanceId As Long) As Long 'A function for getting the ID of an event.
Return InstanceId And &H3FFFFFFF
End Function
Result:
More information can be found in:
Upvotes: 1