Shutdown sequence initialisation

  • Thread starter Thread starter Akshay_Anti
  • Start date Start date
  • Tags Tags
    Sequence
AI Thread Summary
To create a batch file that shuts down a Windows system at a specific time without using Task Scheduler, one approach is to develop a background program or Windows Service that checks the time periodically. This program can utilize the Win32 API to access process information and execute a shutdown command, requiring administrative privileges. It's important to distinguish between windowed and non-windowed processes to ensure that all relevant applications are closed before shutdown. For beginners, using .NET libraries may simplify the process of creating a system service that can run even when the system is rebooted. The shutdown command can be executed with options to force close running applications, though this may risk data loss. Caution is advised, especially on production machines, to avoid unintended shutdowns.
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

Back
Top