CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006
    Posts
    52

    App to turn of computer after some time

    I was wondering if it's possible to write an application that turn's of your computer after an hour, for ex. If it is could someone give me some pointers on how I might go about doing that? Thanks a lot.

  2. #2
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: App to turn of computer after some time

    Hi,

    1) How do I shut down the computer?
    There´s a Win32 API function called InitiateSystemShutdown. Unfortunately you can´t just call it and expect Windows to shut down, you have to enable the SE_SHUTDOWN privilege. A complete example of how to to that can be found here: System shutdown dialog.
    Another way to shut down a computer is to execute "shutdown -s -f".

    2) How do I know when to shut down the computer?
    Define a timestamp (maybe date) when the computer is to be shut down. Periodically check the system time against the timestamp and as soon as you passed shut down the computer as suggested in 1).

    I think there are many free tools that accomplish that task for you, so you don´t have to program that on your own.

    Hth,
    Guido
    - Guido

  3. #3
    Join Date
    Apr 2006
    Posts
    52

    Re: App to turn of computer after some time

    Thanks a lot. I think I'll use shutdown -s -f. Seem the most simple. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured