Shutdown sequence initialisation

  • Thread starter Thread starter Akshay_Anti
  • Start date Start date
  • Tags Tags
    Sequence
Click For Summary

Discussion Overview

The discussion revolves around creating a batch file or program to shut down a Windows system at a specific time, while ensuring that all open programs are closed beforehand. Participants explore various methods to achieve this without using the Windows Task Scheduler and consider the implications of such an approach.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant suggests creating a program that runs in the background, potentially as a system service, to manage the shutdown process at a specified time.
  • Another participant emphasizes the need to distinguish between windowed and non-windowed processes when closing programs before shutdown.
  • There are recommendations to utilize the Win32 API for accessing process information and performing system shutdowns, along with the necessity of having administrative privileges.
  • One participant warns against implementing such a shutdown mechanism on production machines without ensuring that no critical jobs are running, indicating the potential for data loss.
  • Another participant mentions that using .NET libraries might simplify the process for beginners, allowing for the creation of a service that checks the time and executes a shutdown command.
  • There is a suggestion to consider using Autohotkey as an alternative method for automating the shutdown process.

Areas of Agreement / Disagreement

Participants express differing views on the appropriateness and safety of implementing an automated shutdown process. While some provide technical guidance on how to achieve the goal, others caution against the risks involved, particularly in production environments. No consensus is reached on the best approach.

Contextual Notes

The discussion highlights limitations related to the complexity of distinguishing between different types of processes and the potential risks of data loss when forcibly closing applications. There are also unresolved questions regarding the best programming approach and the necessary privileges for executing shutdown commands.

Akshay_Anti
Messages
62
Reaction score
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
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.
 
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
 
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.
 
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.
 
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
 
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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 12 ·
Replies
12
Views
11K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
7K