Thread: How to shutdown (or Restart) a pc with C++

  1. #1
    Unregistered
    Guest

    How to shutdown (or Restart) a pc with C++

    I would like to include an option to sutdown and/or restart the Computer (It is running with win2000pro), but I do not know how !!!
    please help me !


    thx
    Benjamin

  2. #2
    Shadow12345
    Guest
    Okiesmokie


    Senior Member

    Registered: Jan 2002
    Location: Ontario, Canada
    Posts: 134
    Information: Exiting Windows
    This may come to a shock to most of you, but the function to exit windows is.. YES, ExitWindows()



    code:--------------------------------------------------------------------------------
    The ExitWindows function logs the current user off.

    BOOL ExitWindows(

    DWORD dwReserved, // reserved
    UINT uReserved // reserved
    );
    --------------------------------------------------------------------------------


    There is an ExitWindowsEx() function too.


    code:--------------------------------------------------------------------------------
    The ExitWindowsEx function either logs off, shuts down, or shuts down and restarts the system.

    BOOL ExitWindowsEx(

    UINT uFlags, // shutdown operation
    DWORD dwReserved // reserved
    );
    --------------------------------------------------------------------------------


    the flags are:


    quote:
    --------------------------------------------------------------------------------

    EWX_FORCE Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.

    EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.

    EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.

    EWX_REBOOT Shuts down the system and then restarts the system. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.

    EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.

    --------------------------------------------------------------------------------



    Hope that helps you, (none of you probly cared, but.. OH WELL!)

    [EDIT]Tried by best to make the flags readable[/EDIT]

  3. #3
    Shadow12345
    Guest
    I copied that from another post. If you had used the search function you would have been able to find it no problem.

  4. #4
    Unregistered
    Guest
    Ok I gotta ask..What is your quote taken from Shadow12345? And what is the story behind it?

  5. #5
    Shadow12345
    Guest
    my 'quote' is taken from a post off of the C++ board on cprogramming.com from a user named okiesmokie. This happened not too long ago. Story behind it? There is no story, I saw the post, and I decided to copy the information to my computer.

  6. #6
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    One question though...

    What file header is it under? windows.h?

  7. #7
    Shadow12345
    Guest
    Yes it is under windows.h
    sorry

  8. #8
    Registered User Kupo's Avatar
    Join Date
    Dec 2001
    Posts
    36
    isn't it rather obvious that a windows function to be in windows.h?

  9. #9
    Registered User OxYgEn-22's Avatar
    Join Date
    Apr 2002
    Posts
    36
    where else would you find Bill's work?? .. he tries to make sure that everyone has to use his stuff to make their programs run.. is it even possible to make windows includes if you wanted to?

  10. #10
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    ummmmmm unregistered?

    is that you again dayknight?

    trying to make viruses...

  11. #11
    Unregistered
    Guest
    >>is that you again dayknight?
    >>trying to make viruses..

    no it is not...whoever you are talking about and I am not ty\rying to make viruses, but you brought up a nice idea...


    mfg

    theluckyghost

  12. #12
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Yeah, make a virus that restarts the computer!! What will everyone do? There is no cure!

  13. #13
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    Originally posted by MrWizard
    Yeah, make a virus that restarts the computer!! What will everyone do? There is no cure!
    [drops on the floor laughing]

  14. #14
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294

    Re: ummmmmm unregistered?

    Originally posted by heat511
    is that you again dayknight?

    trying to make viruses...
    grr...
    i had stop ciming to this board after that best thread


    bunch of kidz...

  15. #15
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > bunch of kidz...
    What a hipocrite.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to shutdown or restart a PC from a pthread-process
    By mynickmynick in forum C Programming
    Replies: 8
    Last Post: 08-07-2008, 09:11 AM
  2. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  3. Shutdown Pc Timer
    By miranda in forum Windows Programming
    Replies: 10
    Last Post: 12-31-2005, 01:36 AM
  4. Post you pc pics (mods)
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 03-15-2004, 04:15 PM
  5. hOW TO MAKE A PROGRAM WHICH MAKES MY pC TO SHUTDOWN?
    By ALANAIR23 in forum Windows Programming
    Replies: 9
    Last Post: 09-01-2001, 01:27 AM