Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if the computer has been restarted?

Tags:

c#

.net

restart

I once used a command line SMTP mailer that, as a limit of the trial version, allowed you to receive up to 10 emails with it per Windows session. If you rebooted your computer, you could receive 10 more. I thought this kind of shareware crippling was pretty neat, and I'd like to replicate it in my app.

I'm just stuck on how to do it. I know how to limit the user's actions, but how can I tell if the computer has been restarted since the application has been last run?

The OS is Windows and the language is C#.

like image 611
ryeguy Avatar asked Jun 03 '09 20:06

ryeguy


People also ask

How do you tell when a computer has been restarted?

Windows: First you'll need to open up the Event Viewer and navigate to Windows Logs. From there you'll go to the System log and filter it by Event ID 6006. This will indicate when the event log service was shut down, which is one of the last actions to take place prior to rebooting.

How can I tell the last time my computer was restarted?

Open Start. Search for Command Prompt, right-click the top result and click the Run as administrator option. Type the following command to query the device's last boot time and press Enter: systeminfo | find "System Boot Time"

How do I check the restart logs?

1) View Shutdown and Restart Log from Event ViewerType “eventvwr. msc” (no quotes) and hit Enter. The Event Viewer windows will open. After that, navigate to Windows Logs > System on the left pane.

How do I know if Windows 10 restarted?

In Windows, search for and open View advanced system settings. In the Startup and Recovery section, click Settings. Remove the check mark next to Automatically restart, and then click OK. Restart the computer.


1 Answers

You should be able to find events in the event log, such as the event log service start that would tell you if the computer has restarted.

Here's how to read the event log in C#: http://msdn.microsoft.com/en-us/library/k6b9a7h8%28VS.71%29.aspx

// C#
foreach (System.Diagnostics.EventLogEntry entry in EventLog1.Entries) 
{
   Console.WriteLine(entry.Message);
}

Note: you should provide the language and OS you are using.

like image 143
Ravedave Avatar answered Nov 15 '22 05:11

Ravedave