Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Shutdown sequence initialisation

  1. Mar 30, 2013 #1
    Hello,

    How to create a batch file that shuts down system at a particular time (not countdown but when the time approaches, it shuts down the system) after closing all the open programs? I don't want to use task scheduler

    P.S. how to make it a batch file that runs even when the system is off?

    Thanks in advance.
     
  2. jcsd
  3. Apr 1, 2013 #2

    chiro

    User Avatar
    Science Advisor

    Hey Akshay_Anti.

    One problem you might have is to distinguish "windowed" programs vs non-windowed processes (i.e ones that don't have a main window handle and aren't visible in the main taskbar menu).

    What you could do is create a program that runs in the background (like a system service) and then calls a shutdown at a specific time.

    You will have to look at the Win32 API to get access to process information (if you can get proper access) and you may even need to run either a system service or a device driver.
     
  4. Apr 6, 2013 #3
    Could you guide me on how to proceed? I am a new enthusiast and know quite less about the same..

    Thanx
     
  5. Apr 6, 2013 #4

    chiro

    User Avatar
    Science Advisor

    I think the first thing you want to do is to look at writing a Windows Service:

    http://www.muukka.net/programming/service/

    Then you need to get access to process information:

    http://www.codeproject.com/Articles/6072/Win32-APIs-for-Process-Retrieval

    After that, take a look at the Win32 API to perform a system shutdown (you will need security credentials for this):

    http://msdn.microsoft.com/en-us/library/aa376868(VS.85).aspx

    You should also request that your program has the right privileges (Administrative) to run.
     
  6. Apr 6, 2013 #5

    jim mcnamara

    User Avatar

    Staff: Mentor

    Sometimes giving people the answer they want leads to a disaster. If this is any kind of production machine do not do this no matter what you think - until you are completely positive you have a window that is really free of jobs. This is a wonderful way to get a quick exit from a job.

    If this is meant to keep your little brother from playing Starcraft at 4am and later, just create one account, set a password for it, allow no other users access and (windowskey-L) when you leave the computer.

    Obviously, I think it is a bad idea, but running a detached process (service) with time check every 60 seconds, then calling ExitWindowsEx() at the designated time -- is the way to fly. Hopefully into the sunset.
     
  7. Apr 7, 2013 #6

    Filip Larsen

    User Avatar
    Gold Member

  8. Apr 11, 2013 #7

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

  9. Apr 21, 2013 #8

    harborsparrow

    User Avatar
    Gold Member

    If you are a beginner, it will be much easier to write this using .NET libraries rather than the Windows API. The libraries will allow you to create a system service (that runs even after you reboot the machine), awakens periodically to check what time it is, and when ready to kill the system, runs a batch file containing the command "shutdown -f" (or "shutdown -f -r" if you want to reboot). You can optionally provide a user interface for the program in the system tray. If you want to "shut down running programs", the trick will be to know WHICH processes you can safely kill. I'd let the system kill running things, which "shutdown -f" does on Windows. However, it isn't guaranteed to save data of running programs.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Shutdown sequence initialisation
  1. Fibonacci sequence (Replies: 17)

  2. Sequence Diagram (Replies: 0)

Loading...