Quick batch file question

Page 1 of 2 12 LastLast

  1. Posts : 212
    Windows 7 64bit
       #1

    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 Computer


  2. Posts : 1,814
    XP / Win7 x64 Pro
       #2

    Why not just create a batch file that doesn't require user input to back up all your files?
      My Computer


  3. Posts : 212
    Windows 7 64bit
    Thread Starter
       #3

    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


  4. Posts : 1,814
    XP / Win7 x64 Pro
       #4

    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


  5. Posts : 212
    Windows 7 64bit
    Thread Starter
       #5

    o right i see dont mean to sound stupid but how do i go about doing that?
      My Computer


  6. Posts : 1,814
    XP / Win7 x64 Pro
       #6

    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


  7. Posts : 212
    Windows 7 64bit
    Thread Starter
       #7

    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


  8. Posts : 660
    win7
       #8

    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


  9. Posts : 1,814
    XP / Win7 x64 Pro
       #9

    craney5 said:
    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


  10. Posts : 212
    Windows 7 64bit
    Thread Starter
       #10

    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


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 07:17.
Find Us