.bat file help

Status
Not open for further replies.

Johnjohnsenson

Beta member
Messages
3
I'm trying to get a computer (windows XP) to autonomously restart every 24 hours. If I put "shutdown -r -f -t 86400" into the command prompt, it will get the comp to force-restart in 24 hours. however, I want the computer to run this command again when it turns back on without me having to manually imput the command.

I was trying to get a .bat file to run the command, but I can't get it to work. :? Reason I was trying to get a .bat file to run it is then I can tell the comp to run this file on startup.

Anyone have any suggestions? Ideas? Know how to make a .bat or any other file run a command prompt command? Any help is much appreciated. :)
 
I'm not on Windows, but can't you make a .exe (or .bat, or whatever) with the "shutdown -r -f -t 86400" and put a shortcut into the startup applications folder? I'm assuming this would be similar to a .sh file on Ubuntu, where you can simply put the command you want into a .txt file and rename it .sh (or .exe in your case) and make it an application that starts up on boot.
 
Instead of trying to do it the way you are doing it, setup a scheduled task (Start->Programs->Accessories->System Tools->Scheduled Tasks) that will run the batch file everyday at midnight (or whatever time you want). You won't need the -t parameter in your scheduled batch file.
 
@Ifargle Doesn't work on windows... :/

@strollin Thanks, thats a better way to run the file.

I may have not mentioned this clear enough in my original post, but the main issue I'm having here is to make a file of some sort that will run the command. If I just put the command into a .bat or .exe file nothing happens when I run the file.
 
I created a file called sdown.bat that contained 2 lines:

@echo off
shutdown -r -f

I then scheduled the task to run 1 minute in the future. When the minute expired the scheduler ran the bat file and the machine rebooted. Doesn't that work for you?

Actually, you don't even need the batch file, you can set the scheduler to directly run the shutdown.exe in the system32 folder.
 
Thanks strollin, I made that into a .bat file and it made the computer shutdown. It appears the file will only work if it's named "sdown.bat". If I name it "shutdown.bat" (like I had been) it won't work... :hrmph:
 
You could keep the name shutdown.bat if you changed the command to: shutdown.exe -r -f
Otherwise it will attempt to run the shutdown.bat file again.

When you specify only shutdown, the command interpreter will search for shutdown.bat, shutdown.cmd, shutdown.com or shutdown.exe. Since it finds shutdown.bat in the current directory it will run that. Specifying shutdown.exe ensures that only the exe will be run. If, for some reason, there is more than 1 shutdown.exe in the path, it will run the first one it finds. To make sure you run the one intended you could specify the exact path such as

C:\windows\system32\shutdown.exe -r -f

If you set the scheduler to execute the shutdown.exe and drop the batch file, the problem is also eliminated.
 
Status
Not open for further replies.
Back
Top Bottom