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
craney5

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
FliGi7

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
craney5

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
FliGi7

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
craney5

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
FliGi7

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
craney5

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
wilywombat

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
FliGi7

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
craney5

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




Similar help and support threads
Thread Forum
batch file question
I have a batch file to restart windows and want to do on a schedule. shutdown.exe /r /t 00 But when i try it manually or try to restart from start/restart there are programs running in the background and i have to force restart. What do i add to the batch file to stop the programs or force...
General Discussion
Task Scheduling With Batch File Question
Hi everyone, I've recently been setting up some automation via TS with great success, until now. I want it to delete daily all content, sub folders and files etc from my TV shows parent folder. I am using the following shell script (.cmd batch file) @echo off setlocal...
Performance & Maintenance
Can I mass apply RAA using a batch file or other quick trick?
I was wondering if there was a way to easily apply RAA to multiple (read 50+) .exe files on a system. We put systems out that require multiple exe files to have this setup and it takes time to go through and click each one. Could it be done by doing a registry batch file? Or AutoIT or other...
Software
Newb, Win 7 Batch file question-KVM switching
hello Sorry if I'm posting this to the wrong place, but I'm not sure what this would be classed under. I would like to be able to change between the two computers connected to my KVM by clicking on an icon. My Belkin KVM has a remote switch that should be on my desktop, but my two cats...
General Discussion
Need Help- Quick Batch File / Location
Hello we are running Windows 7 Enterprise x32 When you click on the Start Button Win7 has the Projector mode toggle. They want it to Automatically Clone with no choice needed by our "lazy" users. Now the word is Duplicate on the toggle bar so I am not sure which word to use. NOR am I...
General Discussion


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 21:02.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App