Simple code. it creates a batch file that shuts down machine on a timer using windows command prompt command shutdown -s -t xxx. the xxx is a variable named sec. I used cout and cin to ask for minutes variable name mins. I multiplied by 60 to get seconds. I closed the batch file. I used system to open the file and commence the shutdown process. Everything works perfect!
The problem is that the exe and the batch file disappear completely after the first execution of the code. Not by running in IDE, but by actually clicking the EXE. It works but then its gone. I have been all day working on tryna fix it. I know its stupid simple and believe its windows defender.
I have tried on 2 machines, win 10 and 8.1.
So frustrated at myself for not figuring this out seems so simple lol.
Code is below.
THANKS IN ADVANCE TO EVERYONE!!
using namespace std;
cout<<"Enter in how minutes you would like your computer to remain powered on and press enter... \n";
Sec = Mins * 60;
OutputFile<<"shutdown -s -t "<<Sec;
Yea i Have a win 7 machine. I need to try it on It prob will work on there. I made the program for when people want to fall asleep binge watching netflix series but dont want pc on all night. I actually made it for my wife lol. Anyways, Thanks alot for your responses and I will try the CreateProcess() instead. hopefully this will work. I'll kepp you guys posted. Thanks again!
Thank you all for your responses! I have finally figured it out and learned a little more from each of you guys recommendations. The program works perfectly and may come in handy if you want a copy. If you copy this code and compile it save the exe in a folder place that folder anywhere. the batch file will be created to that folder. create a shortcut of the exe and put it on your desktop. bam! now you have a shutdown timer! I call it Shut Eye.I made it fore my wife who binge watches netfilx and leaves her computer on all night. lol
anyways here is the code!
using namespace std;
ok, its neat to learn how to do this but all you needed was a 1-2 line batch file. Now see if you can do it that way ... batch files are a great thing to know, and can be used with your programs, inside them, alongside them, etc to do more stuff with less work. Its even more potent if you put something like cygwin on your PC and hack the path so that from a dos prompt you can call the linux commands...