Shutdown sequence initialisation

  • Thread starter Akshay_Anti
  • Start date
  • Tags
    Sequence
In summary: It is better to send a command to the programs you want to close and let them close themselves safely. This is often done by sending them a WM_CLOSE message. However, it is up to each program to decide what to do when it gets that message.You can use .NET libraries to create a system service that runs in the background and checks the time periodically. When it is time to shut down the system, it can run a batch file with the command "shutdown -f" (or "shutdown -f -r" to reboot). It is important to note that this may not save data of running programs, so it is better to send a command to the programs to close themselves safely. This can be done by sending a
  • #1
Akshay_Anti
62
0
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.
 
Technology news on Phys.org
  • #2
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.
 
  • #3
chiro said:
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.

Could you guide me on how to proceed? I am a new enthusiast and know quite less about the same..

Thanx
 
  • #4
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.
 
  • #5
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.
 
  • #6
Perhaps you can use the Windows Task Scheduler, as in http://www.sevenforums.com/tutorials/95316-task-scheduler-create-shut-down-pc-automatically-task.html
 
  • #8
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.
 

Related to Shutdown sequence initialisation

1. What is a shutdown sequence initialisation?

A shutdown sequence initialisation is a process that occurs when a computer or system is being powered down. It involves a series of steps that ensure all running processes are properly closed and data is safely saved before the system shuts down completely.

2. Why is a shutdown sequence initialisation important?

A shutdown sequence initialisation is important as it helps prevent data loss and ensures that the system is shut down properly. It also helps prevent any potential damage to hardware components due to sudden power loss.

3. How does a shutdown sequence initialisation work?

A shutdown sequence initialisation works by sending signals to all running processes, notifying them to save any unsaved data and close properly. Once all processes have been closed, the system will then shut down the operating system and power off the hardware components.

4. What happens if a shutdown sequence initialisation is interrupted?

If a shutdown sequence initialisation is interrupted, it can lead to data loss or corruption as processes may not have been properly closed. It can also cause system errors or damage to hardware components if the system is not shut down properly.

5. Can a shutdown sequence initialisation be customized?

Yes, a shutdown sequence initialisation can be customized by adjusting the settings in the operating system. Some systems may have default settings for the shutdown sequence, but users can modify these settings to fit their specific needs or preferences.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
12
Views
9K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
22
Views
963
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
4
Views
767
  • Programming and Computer Science
Replies
8
Views
401
  • Programming and Computer Science
Replies
3
Views
4K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
0
Views
602
Back
Top