How do I code computer shutdown?

I have computer addiction and need a program that will help me break it. Unfortunately, I couldn't find a program that has all the features I need. (I won't list them as they are irrelevant to the topic.) So I decided to make one myself, which will be my first project after finishing beginner C++ online course. My question is as the title says. I'm aware I shouldn't be asking for an entire code, but I'm still a beginner and need to get this done as soon as possible before the addiction ruins my life.
Operating system?
I made a program where you enter a program and then after time up it displays a message box telling "Time up". I have been thinking about modifying it to close. Look at this website http://www.aumha.org/win5/a/shutcut.php for a shutdown utility.
Last edited on
As much as people hate to admit it, you could have a program that prompts you for a time, then you use Sleep() [assuming you're on windows] on the time that is inputted, then use system(). System is the part that people hate. If you don't know what it is, it's a function to execute a command-line function, but it's "a security hole" but since this program is most likely for only you, you could use the regular Windows shutdown command (again assuming you're on windows) with system after using wait. you'd have a command prompt window running in the background but hey, it'd use a minimal amount of processing power as it'd mostly just be waiting. So, it should look something like this.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <stdlib.h>
#include <Windows.h>

int main() {	
	int mins;
	cout << "Time (Minutes) > ";
	cin >> mins;
	Sleep(mins*10000);
	system("shutdown");
}
Or you could use SetSystemPowerState().
Topic archived. No new replies allowed.