What is Strict Time?
Strict Time is an app created by the author of this blog Nikhil Harry (@nikhilhex). Strict Time was created in C# using Windows Forms. Strict Time is licensed under GPL-2.0. You can contribute to Strict Time here.
What does Strict Time do?
As you see in the title, I put:
Turn off your computer. For good.
Have you ever had to go somewhere? A meeting, home from work, to work, you’re just working on that one project then you end up being late? Just turn on Strict Time and it will turn off your computer at the exact time you enter and gives you the option to have a warning display or no warning display. You can’t cancel your shut down though that is planned to be added.
How does Strict Time work?
Jumping into the code of Strict Time, when you click the Start button to prepare the shutdown here is what it does:
-
Create a Timer and make it tick every 100 ms (to be honest, 60000 ms would be the best because I removed implementation for entering seconds)
- Check to see if it’s time to turn off the computer using:
// dtp is the timer Math.Floor(((TimeSpan)dtp.Value.TimeOfDay - DateTime.Now.TimeOfDay).TotalSeconds) == 0
-
Check what the user entered in a switch statement.
- Run
Process.Start()
to shut down the computer. Read my last post (except the sleep command that doesn’t useProcess.Start()
).
The entire code looks like this:
if (Math.Floor(((TimeSpan)dtp.Value.TimeOfDay - DateTime.Now.TimeOfDay).TotalSeconds) == 0)
{
switch (comboBox1.Text)
{
case "Log Out":
Process.Start(@"C:\Windows\System32\cmd.exe", "/C shutdown /l");
break;
case "Hibernate":
Process.Start(@"C:\Windows\System32\cmd.exe", "/C shutdown /h");
break;
case "Sleep":
Process.Start(@"C:\Windows\System32\cmd.exe", "/C rundll32.exe powrprof.dll, SetSuspendState Sleep");
break;
case "Shut Down":
Process.Start(@"C:\Windows\System32\cmd.exe", "/C shutdown /s");
break;
case "Shut Down (No Warning)":
Process.Start(@"C:\Windows\System32\cmd.exe", " /C shutdown /p");
break;
}
Conclusion
If you need Strict Time, it’s possible to navigate to the repo I linked above and click on the latest release. I won’t be posting next week though the week prior, I can post.