Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Quick batch file question


27 Oct 2010   #1

Windows 7 64bit
 
 
Quick batch file question

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 System SpecsSystem Spec
.

27 Oct 2010   #2

XP / Win7 x64 Pro
 
 

Why not just create a batch file that doesn't require user input to back up all your files?
My System SpecsSystem Spec
27 Oct 2010   #3

Windows 7 64bit
 
 

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 System SpecsSystem Spec
.


27 Oct 2010   #4

XP / Win7 x64 Pro
 
 

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 System SpecsSystem Spec
27 Oct 2010   #5

Windows 7 64bit
 
 

o right i see dont mean to sound stupid but how do i go about doing that?
My System SpecsSystem Spec
27 Oct 2010   #6

XP / Win7 x64 Pro
 
 

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 System SpecsSystem Spec
28 Oct 2010   #7

Windows 7 64bit
 
 

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 System SpecsSystem Spec
28 Oct 2010   #8

win7
 
 

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 System SpecsSystem Spec
28 Oct 2010   #9

XP / Win7 x64 Pro
 
 

Quote   Quote: Originally Posted by craney5 View Post
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 System SpecsSystem Spec
28 Oct 2010   #10

Windows 7 64bit
 
 

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 System SpecsSystem Spec
Reply

 Quick batch file question




Thread Tools




Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 03:20 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33