Thread: Restarting computer

  1. #1
    Aspiring "Software Guy"
    Join Date
    Aug 2005
    Posts
    46

    Restarting computer

    Is it possible to make the user's computer restart, from within a c++ console program?

  2. #2
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    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.

  3. #3
    Aspiring "Software Guy"
    Join Date
    Aug 2005
    Posts
    46
    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....

  4. #4
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    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.


  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    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?

  6. #6
    Aspiring "Software Guy"
    Join Date
    Aug 2005
    Posts
    46
    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...

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    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?

  8. #8
    Aspiring "Software Guy"
    Join Date
    Aug 2005
    Posts
    46
    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)

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    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?

  10. #10
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by sreetvert83
    so system("shutdown -s -tt 01"); should shutdown the comp
    you should be able to understand that right?
    But why would he want to? I agree with treenef on this one - it seems a little out of place here on cboard...
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    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?

  12. #12
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by pritin
    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...
    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.

    I believe someone posted the win32 version to forcefully shutdown, commands from MSDN, in a topic not long ago. Might search 'system shutdown'.

    If a mime dies in the woods and no one is around to hear it, does it make a sound?
    Did it make a sound dying?
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  13. #13
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    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.

  14. #14
    Registered User
    Join Date
    Aug 2005
    Posts
    31
    If a mime dies in the woods and no one is around to hear it, does it make a sound?
    It sounds like Pratchett. And it does because there are animals that can hear it.

  15. #15
    Registered User
    Join Date
    Sep 2005
    Location
    USA
    Posts
    69
    Just curious,
    Why do you want to restart the user's computer?
    -Adam

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 02-26-2006, 01:16 PM
  2. Major Computer Problem
    By Olidivera in forum Tech Board
    Replies: 10
    Last Post: 07-15-2005, 11:15 AM
  3. Tabbed Windows with MDI?
    By willc0de4food in forum Windows Programming
    Replies: 25
    Last Post: 05-19-2005, 10:58 PM
  4. Computer will not boot.
    By RealityFusion in forum Tech Board
    Replies: 25
    Last Post: 09-10-2004, 04:05 PM
  5. Randomly Restarting Computer
    By DirX in forum Tech Board
    Replies: 19
    Last Post: 03-25-2003, 03:00 PM