Quick batch file question

craney5

New member
Power User
Local time
12:03 AM
Messages
212
Hi,

I have just created a batch file to backup a few things on my machine, the thing is the batch file has a menu in it and i was wondering if i was to set the batch file to run under task scheduler say once a week is there a way i can get it to excute through the menu of the batch file? if not when the task scheduler runs it, it will just stay a point waiting for me to press enter.

I have put a part of the batch file below to show you what i have done.

@ECHO OFF
ECHO WELCOME TO LIAM'S BACKUP WIZARD
GOTO MENU
:MENU
ECHO PLEASE SELECT A COMMAND BELOW BY PRESSING NUMBERS 1-4 FOR THE ITEMS THAT YOU WISH TO BACKUP
ECHO ===== BACKUP MENU LIST =====
ECHO 1. iTUNES MUSIC BACKUP
ECHO 2. MY PICTURES BACKUP
ECHO 3. FOOTBALL MANAGER 2011 BACKUP
ECHO 4. QUIT
SET /P N=TYPE 1, 2, 3 OR 4 THEN PRESS ENTER:
IF "%N%"=="1" GOTO iTUNES
IF "%N%"=="2" GOTO MY PICTURES
IF "%N%"=="3" GOTO FOOTBALL MANAGER 2011
IF "%N%"=="4" GOTO QUIT
:iTUNES
ECHO YOU HAVE CHOSEN TO BACKUP THE iTUNES MUSIC FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /L /E /D /Y
PAUSE
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /E /D /Y >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
GOTO MENU

: MY PICTURES
ECHO YOU HAVE CHOSEN TO BACKUP THE MY PICTURES FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /L /E /D /Y
PAUSE
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /E /D /Y >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
GOTO MENU

Hope you can help

Many thanks
 

My Computer

OS
Windows 7 64bit
CPU
Phenom IIx4 955 Black Edition
Memory
4GB Kingston 1066mhz DDR2
Graphics Card(s)
Gigabyte 260GTX
Monitor(s) Displays
Samsung syncmaster 2033
Hard Drives
500GB Samsung ATA
500GB Segate ATA
PSU
Antec True blue 750W Modular
Case
Antec 1200
Cooling
Prolimatech Megahalems Performance CPU Cooler/2x Apache Fan
Why not just create a batch file that doesn't require user input to back up all your files?
 

My Computer

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
yea i know what you mean mate its just i wanted to have a play around with my batch and see if it was possible thats all
 

My Computer

OS
Windows 7 64bit
CPU
Phenom IIx4 955 Black Edition
Memory
4GB Kingston 1066mhz DDR2
Graphics Card(s)
Gigabyte 260GTX
Monitor(s) Displays
Samsung syncmaster 2033
Hard Drives
500GB Samsung ATA
500GB Segate ATA
PSU
Antec True blue 750W Modular
Case
Antec 1200
Cooling
Prolimatech Megahalems Performance CPU Cooler/2x Apache Fan
You could also alter the batch file to check for command line arguments before going to the main menu, at which point you could set task scheduler to run the program with a particular argument that would set it into autonomous mode that didn't require user interaction.
 

My Computer

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
o right i see dont mean to sound stupid but how do i go about doing that?
 

My Computer

OS
Windows 7 64bit
CPU
Phenom IIx4 955 Black Edition
Memory
4GB Kingston 1066mhz DDR2
Graphics Card(s)
Gigabyte 260GTX
Monitor(s) Displays
Samsung syncmaster 2033
Hard Drives
500GB Samsung ATA
500GB Segate ATA
PSU
Antec True blue 750W Modular
Case
Antec 1200
Cooling
Prolimatech Megahalems Performance CPU Cooler/2x Apache Fan
IF "%1"=="" GOTO Continue

%1 is the first command line argument you pass to the program. So, you could run the program like the following:

"backup.bat all"

Then, have the following line in the program before the GOTO MENU:

IF "%1"=="all" GOTO ITUNES

Then, at the end of the ITUNES block, have a line that says:

IF "%1"=="all" GOTO MYPICTURES
GOTO MENU

And so forth. Hopefully you can get the idea of what I'm saying.
 

My Computer

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
I have had a play around with it and didnt realize there was a timeout command TIMEOUT /T 10, i have put this into the batch file but all i need to know now is what command to put after the timer to say "if the timer runs out go to here" if you see what i mean. I know if i press enter it will go to my backup menu, so im looking to set it to go to a different menu if there timer run out

GOTO MENU
:MENU
ECHO PLEASE SELECT A COMMAND BELOW BY PRESSING NUMBERS 1-4 FOR THE ITEMS THAT YOU WISH TO BACKUP
ECHO ===== BACKUP MENU LIST =====
ECHO 1. iTUNES MUSIC BACKUP
ECHO 2. MY PICTURES BACKUP
ECHO 3. FOOTBALL MANAGER 2011 BACKUP
ECHO 4. QUIT
TIMEOUT /T 10 (IF THIS TIMER RUNS OUT I WANT IT TO GO TO A DIFFERENT MENU)
SET /P N=TYPE 1, 2, 3 OR 4 THEN PRESS ENTER:
IF "%N%"=="1" GOTO iTUNES
IF "%N%"=="2" GOTO MY PICTURES
IF "%N%"=="3" GOTO FOOTBALL MANAGER 2011
IF "%N%"=="4" GOTO QUIT
 

My Computer

OS
Windows 7 64bit
CPU
Phenom IIx4 955 Black Edition
Memory
4GB Kingston 1066mhz DDR2
Graphics Card(s)
Gigabyte 260GTX
Monitor(s) Displays
Samsung syncmaster 2033
Hard Drives
500GB Samsung ATA
500GB Segate ATA
PSU
Antec True blue 750W Modular
Case
Antec 1200
Cooling
Prolimatech Megahalems Performance CPU Cooler/2x Apache Fan
Just my 2 cents worth...Have you investigated Winbatch at WinBatch®, the batch language for Windows, your scripting solution. ? You can download a trial copy to test and it allows you to control anything virtually, all in a windows environment. By anything I mean anything, from registry entries , serial and parallel ports, web page downloads, any sort of scripts you can dream of. Give it a go, I use it all the time for controlling machines and pushing and pulling huge datasets around via ftp or telnet.
 

My Computer

OS
win7
I have had a play around with it and didnt realize there was a timeout command TIMEOUT /T 10, i have put this into the batch file but all i need to know now is what command to put after the timer to say "if the timer runs out go to here" if you see what i mean

That's another way of doing what I just described. Either way will do the same thing.
 

My Computer

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
Thanks again for your input really appreciate it. What im trying to do is find the right command to put next to the TIMEOUT /T 10 say if the timer run out please go to a different menu (auto menu for example which i have not put into this batch file yet) where as if i press enter normally it goes to my normal backup menu
 

My Computer

OS
Windows 7 64bit
CPU
Phenom IIx4 955 Black Edition
Memory
4GB Kingston 1066mhz DDR2
Graphics Card(s)
Gigabyte 260GTX
Monitor(s) Displays
Samsung syncmaster 2033
Hard Drives
500GB Samsung ATA
500GB Segate ATA
PSU
Antec True blue 750W Modular
Case
Antec 1200
Cooling
Prolimatech Megahalems Performance CPU Cooler/2x Apache Fan
Hi Liam,

I added a line underneath your timeout that piped the program to a subroutine called net_action wich is at the bottom of the script. Note I have added a pause statement after so that you can see that it does indeed pipe to the subroutine because the batch program would terminate otherwise, as soon as it echo'd the "here" statement. Remove this and add you new segment instead.

@ECHO OFF
ECHO WELCOME TO LIAM'S BACKUP WIZARD
GOTO MENU
:MENU
ECHO PLEASE SELECT A COMMAND BELOW BY PRESSING NUMBERS 1-4 FOR THE ITEMS THAT YOU WISH TO BACKUP
ECHO ===== BACKUP MENU LIST =====
ECHO 1. iTUNES MUSIC BACKUP
ECHO 2. MY PICTURES BACKUP
ECHO 3. FOOTBALL MANAGER 2011 BACKUP
ECHO 4. QUIT
TIMEOUT /T 10
goto next_action

SET /P N=TYPE 1, 2, 3 OR 4 THEN PRESS ENTER:
IF "%N%"=="1" GOTO iTUNES
IF "%N%"=="2" GOTO MY PICTURES
IF "%N%"=="3" GOTO FOOTBALL MANAGER 2011
IF "%N%"=="4" GOTO QUIT
:iTUNES
ECHO YOU HAVE CHOSEN TO BACKUP THE iTUNES MUSIC FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /L /E /D /Y
PAUSE
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /E /D /Y >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
GOTO MENU

: MY PICTURES
ECHO YOU HAVE CHOSEN TO BACKUP THE MY PICTURES FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /L /E /D /Y
PAUSE
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /E /D /Y >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
GOTO MENU

: next_action

Echo here

PAUSE
 

My Computer

OS
win7
You don't need that next_action call or routine. You just need to put an if statement before the end of each sections GOTO command that checks if the command line variable is set, if not it goes back to the menu, otherwise it goes to the next section in an automated fashion. Again, that is what my posts earlier describe rather than having to put a whole new subsection that just adds duplicate code to the program, but I can only lead a horse to water.
 

My Computer

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
@FliGi7, The OP changed their requirement in their fourth post on page 1 so that they could jump to a new code section on timeout occurring, that is why I posted my suggestion. Had the requirement stayed the same I would not have suggested the action I did.
 

My Computer

OS
win7
Totally understood. I wasn't addressing that toward you, you are simply helping like I am. I was just saying that my solution doesn't require the extras that are coming about from the change the OP wants or thinks he needs now. If I'm understanding his problem correctly, following my instructions will do exactly what he wants with the least amount of extra code added. Or, I could be wrong and he could want something different that I'm not understanding.
 

My Computer

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
FliGi7 your spot on with what i am trying to do! to be honest i dont want to set up a duplicate command of all the menus that i have created for when the timer runs out. What i am trying to do is if i hit enter before the time runs out i can manually pick out of the 4 menus which one i want to back up and when i set it up on the task schedule and the timer runs out i want a command to run and back up all of the 4 menus automatically. Its just finding the right command to add after the timer runs out and adding something in at the end of every menu.

I know im proberly sounding really confusing sorry

willywombat- thanks so much for your input much appreciated
 

My Computer

OS
Windows 7 64bit
CPU
Phenom IIx4 955 Black Edition
Memory
4GB Kingston 1066mhz DDR2
Graphics Card(s)
Gigabyte 260GTX
Monitor(s) Displays
Samsung syncmaster 2033
Hard Drives
500GB Samsung ATA
500GB Segate ATA
PSU
Antec True blue 750W Modular
Case
Antec 1200
Cooling
Prolimatech Megahalems Performance CPU Cooler/2x Apache Fan
@ECHO OFF
ECHO WELCOME TO LIAM'S BACKUP WIZARD

IF %1 == "auto" GOTO ITUNES

GOTO MENU
:MENU
ECHO PLEASE SELECT A COMMAND BELOW BY PRESSING NUMBERS 1-4 FOR THE ITEMS THAT YOU WISH TO BACKUP
ECHO ===== BACKUP MENU LIST =====
ECHO 1. iTUNES MUSIC BACKUP
ECHO 2. MY PICTURES BACKUP
ECHO 3. FOOTBALL MANAGER 2011 BACKUP
ECHO 4. QUIT
SET /P N=TYPE 1, 2, 3 OR 4 THEN PRESS ENTER:
IF "%N%"=="1" GOTO iTUNES
IF "%N%"=="2" GOTO MY PICTURES
IF "%N%"=="3" GOTO FOOTBALL MANAGER 2011
IF "%N%"=="4" GOTO QUIT
:iTUNES
ECHO YOU HAVE CHOSEN TO BACKUP THE iTUNES MUSIC FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /L /E /D /Y
PAUSE
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /E /D /Y >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
IF %1 == "auto" GOTO MYPICTURES
GOTO MENU

: MYPICTURES
ECHO YOU HAVE CHOSEN TO BACKUP THE MY PICTURES FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /L /E /D /Y
PAUSE
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /E /D /Y >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
IF %1 == "auto" EXIT
GOTO MENU



Without having run this myself to check, that should do what you're asking.

In task scheduler have the command run with the argument auto.

http://www.sevenforums.com/tutorials/12444-task-scheduler-create-new-task.html

You would configure this in #7 of the above tutorial.
 

My Computer

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
Thanks so much mate i will give this a try and let you know who it goes

Thanks again
 

My Computer

OS
Windows 7 64bit
CPU
Phenom IIx4 955 Black Edition
Memory
4GB Kingston 1066mhz DDR2
Graphics Card(s)
Gigabyte 260GTX
Monitor(s) Displays
Samsung syncmaster 2033
Hard Drives
500GB Samsung ATA
500GB Segate ATA
PSU
Antec True blue 750W Modular
Case
Antec 1200
Cooling
Prolimatech Megahalems Performance CPU Cooler/2x Apache Fan
Hi matey i have created a shortcup to my batch file and whenver i try and add "auto backup" to the end of the target line it keeps say the specified target line is not valid. This is what i have done
"C:\Users\Liam\Desktop\Backup Batch Files\Liam's Auto Backup Wizard.bat auto backup"

In the batch file at the top before the "goto menu" option i have put

IF "%1"=="AUTO BACKUP" GOTO AUTO BACKUP

I have added a auto backup menu at the bottom of the batch file with no prompts

:AUTO BACKUP
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /E /D /Y >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /E /D /Y >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\Football Manager 2011\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\Football Manager 2011\BACKUP LOG.TXT
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\Football Manager 2011\BACKUP LOG.TXT"
XCOPY "C:\Users\Liam\Documents\Sports Interactive\Football Manager 2011 Demo\games" "I:\Liam\XCOPY Backup Files\Football Manager 2011" /E /D /Y >> "I:\Liam\XCOPY Backup Files\Football Manager 2011\BACKUP LOG.TXT"
CLS

I have also tried entering the following arguments in task schedular
%1
"%1"
Auto Backup

Im kinda new to this so still learning my way around but just cant get it to by pass my standard goto menu
 

My Computer

OS
Windows 7 64bit
CPU
Phenom IIx4 955 Black Edition
Memory
4GB Kingston 1066mhz DDR2
Graphics Card(s)
Gigabyte 260GTX
Monitor(s) Displays
Samsung syncmaster 2033
Hard Drives
500GB Samsung ATA
500GB Segate ATA
PSU
Antec True blue 750W Modular
Case
Antec 1200
Cooling
Prolimatech Megahalems Performance CPU Cooler/2x Apache Fan
Try adding an underscore between the words auto and backup in both the shortcut and in the program. This is because the words auto and backup seperated by a space in the command line would be interpreted as 2 seperate paramenters.
 

My Computer

OS
win7
^ What wily said.

It has to be one contiguous word or it will be interpreted as two separate arguments (separated by a space), which is what it is doing. So your program is seeing that %1== "Auto" and is not hitting that routine.
 

My Computer

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
Back
Top