Is it possible to make the user's computer restart, from within a c++ console program?
Is it possible to make the user's computer restart, from within a c++ console program?
Yes, but as you can imagine such code is dangerous in the wrong hands. But if you search hard enough you will eventually find what you are looking for. If you are using Microsoft there a few generic keywords used to either, shutdown,restart,or log off users. If you are using linux, you can shut down from the shell command line.
Try searching Microsoft's website for ideas.
I am using Windows, and the user of my program will be too.
I dont remember properly, but io remember having read in some thread that closing one of the processes, will give the user 45 secs to save his work, before shutdown....
hmm, I have the code here which would shutdown/ restart/logoff a user immediately after execution.
But as I have mentioned before, such code would be considered dangerous, for the simple reason one could send it as a zipped file by email and upon execution it would shutdown that person's computer. So I'd rather not post it. Sorry.
well anyone who knows dos knows that shutdown -s will do a 30 second countdown and shut off the computer and anyone who knows c++ even a little bit knows the system(""); stuff so shutting down a comp from within a c++ program is rather easy, and i dont think its that dangerous now the format command.... thats bad stuff
If a mime dies in the woods and no one is around to hear it, does it make a sound?
I'm new to c++ and i hardly know DOS. I know the system pause, title, md , cd etc.. commands but not this one.
Could someone plztell me how its done?
Thanks.
And treenef, believe me, im not going to misuse it or anything...
system(" "); anything in the " " is a dos command so
system("shutdown -s"); would shutdown the computer, why would you want to though? shutdown -s gives a 30 second count then shuts down, i think you can change this, to find out go to start>run> type command.com>then type shutdown /? any dos commands will work in the system("");
If a mime dies in the woods and no one is around to hear it, does it make a sound?
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-2001.
C:\>shutdown /?
Usage: SHUTDOWN [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "c
omment"] [-d up:xx:yy]
No args Display this message (same as -?)
-i Display GUI interface, must be the first option
-l Log off (cannot be used with -m option)
-s Shutdown the computer
-r Shutdown and restart the computer
-a Abort a system shutdown
-m \\computername Remote computer to shutdown/restart/abort
-t xx Set timeout for shutdown to xx seconds
-c "comment" Shutdown comment (maximum of 127 characters)
-f Forces running applications to close without war
ning
-d [u][p]:xx:yy The reason code for the shutdown
u is the user code
p is a planned shutdown code
xx is the major reason code (positive integer le
ss than 256)
yy is the minor reason code (positive integer le
ss than 65536)
so system("shutdown -s -tt 01"); should shutdown the comp
you should be able to understand that right?
If a mime dies in the woods and no one is around to hear it, does it make a sound?
But why would he want to? I agree with treenef on this one - it seems a little out of place here on cboard...Originally Posted by sreetvert83
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
i dont know why he would want to, but i like show people what i know, its not my place to know what he uses it for, he would just find it out somewhere else, besides if he wanted to shut someones comp off there are easyer ways to do it than with c++ batch for example, but i have to agree there is no reason to shut down your computer with a c++ prog. i hope everyone knows where im coming from
If a mime dies in the woods and no one is around to hear it, does it make a sound?
I dont know why you would want to know those commands.. system("") sucks. Let alone would I see the point of knowing this specific one.Originally Posted by pritin
I believe someone posted the win32 version to forcefully shutdown, commands from MSDN, in a topic not long ago. Might search 'system shutdown'.
Did it make a sound dying?If a mime dies in the woods and no one is around to hear it, does it make a sound?
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101
If you really want to do it, do it right. Use one of these.
Your application will need special priviledges, namely SE_SHUTDOWN_NAME to execute this commands successfully. It's up to you to find out how to get these priviledges.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
It sounds like Pratchett. And it does because there are animals that can hear it.If a mime dies in the woods and no one is around to hear it, does it make a sound?
Just curious,
Why do you want to restart the user's computer?
-Adam