Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to make a simple exe file with a datagrid of the info of the times the current user:

1- Logged in.
2- Logged out.
3- Restarted PC.
4- Shut down PC.
5- Turned on PC.
6- Hibernated PC.
7- Suspended (sleep) PC.

And I would list them by time, for example if the user took the meds when he turned on his PC or woke it up from sleep and needs to know when that happened to backtrack taking his meds he would open this exe file to see the times.

What I have tried:

Looking in Windows Event Viewer to the index number of these actions.
Posted
Updated 13-Dec-20 7:07am
Comments
[no name] 13-Dec-20 11:20am    
Yep. Keep looking at the Windows events. That's where it is. Next you write a report.
john1990_1 13-Dec-20 13:19pm    
I almost did it all, check my answer and see if you can provide me with the event IDs please...

1 solution

With:

using System.Diagnostics;

foreach (EventLog log in EventLog.GetEventLogs())
            {
                if (log.Log == "Security")
                {
                    foreach (EventLogEntry e in log.Entries)
                    {
                        switch (e.InstanceId)
                        {
                            case 4672:
                                dataGridViewNamesAndTimes.Rows.Add("Special Logon", e.TimeGenerated);
                                break;

                            case 4625:
                                dataGridViewNamesAndTimes.Rows.Add("An account failed to log on", e.TimeGenerated);
                                break;
                        }
                    }
                    break;
                }
            }


I now only need to check the InstanceId in Windows Security Log Events[^] and check which events I want to show in the datagrid, with checkboxes to toggle show/hide of each of the event Ids...

Would someone please help me find the InstanceIds of these actions since the explanations in the link above aren't always accurate and are fuzzy?

When the user:
1- Logged in.
2- Logged out.
3- Restarted PC.
4- Shut down PC.
5- Turned on PC.
6- Hibernated PC.
7- Suspended (sleep) PC.
 
Share this answer
 
v5

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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