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#.
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.
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"
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With