3

I am going crazy over a "pause" statement not working a batch file I made to clean USB drives from a virus which seems to be widespread where I work.

I found out from my researches that such problems may occur when you call another batch file and it fails or has an exit statement, and used "call" to prevent it from happening.

The problem is, the batch file keeps going, it does not stop, it works quite nicely, but it just ignores all but the first pause occurence.

Another thing is, when I use @echo off, it won't work no matter what. If I REM @echo off and run the batch from cmd, pauses will fail on the first run, then if I run it one more time then pauses will work just fine.

I just can't seem to fine why this happens despite looking for solutions all over the internet.

I left the vanity title/signature thingy only because it might be one of the reason, but I did try without it and it still would not work.

Here is the code:

@echo off
mode con: cols=80 lines=30
title USBFix by Tamok

:Signature
echo " __    __       _______..______    _______  __  ___   ___"
echo "|  |  |  |     /       ||   _  \  |   ____||  | \  \ /  /"
echo "|  |  |  |    |   (----`|  |_)  | |  |__   |  |  \  V  / "
echo "|  |  |  |     \   \    |   _  <  |   __|  |  |   >   <  "
echo "|  `--'  | .----)   |   |  |_)  | |  |     |  |  /  .  \ "
echo " \______/  |_______/    |______/  |__|     |__| /__/ \__\"
echo Par T. Tamok
echo Version 0.1
echo.
echo.
echo Bienvenue dans le programme de desinfection de clefs USB et volumes externes. Appuyez sur une touche pour continuer.
pause >nul
echo.
echo Voici une liste des disques reconnus sur votre ordinateur.
echo.
call wmic logicaldisk get caption,providername,drivetype,volumename
echo.

:Volume Check
    set /p vName=Veuillez saisir la lettre correspondant au volume que vous souhaitez reparer : 
    if not exist %vName%:\nul goto :failed

:Repair
    echo Appuyez sur une touche pour continuer la reparation ou fermez la fenetre pour quitter.
    pause >nul
    echo Reparation en cours, veuillez patienter...
    call attrib -h -r -s /s /d %vName%:\*.*
    echo Restauration des fichiers caches terminee. Suppression des fichiers infectes...
    if exist %vName%:\iTunesHelper.vbe goto :vbdel
    echo Pas de virus iTunesHelper.vbe.
    :keep1
    if exist %vName%:\*.lnk goto :lnkdel
    echo Pas de fichiers .lnk.
    :keep2
    goto :eof

:failed
    echo Cette lettre ne correspond a aucun volume. Appuyez sur une touche pour quitter.
    goto :eof

:vbdel
    del %vName%:\iTunesHelper.vbe
    echo Virus iTunesHelper.vbe repere.
    echo Suppression de iTunesHelper.vbe OK.
    goto keep1

:lnkdel
    del %vName%:\*.lnk
    echo Suppression des fichiers .lnk OK.
    goto keep2

:eof
    pause >nul
    :exit
3
  • 1
    There doesn't seem to be any problems. Maybe try the sleep command and see what happens (or remove the redirection to nul) Commented Jun 16, 2014 at 8:37
  • Non interactivity. If pause doesn't think a human can press any key, it does not pause. I do not know the rules but startup scripts are one example. Although looking at yourcode it is probably script error. Commented Jun 16, 2014 at 9:07
  • @Monacraft I tried to remove the redirection to nul, doesn't change anything sadly. I then tried replacing pause with timeout, and it worked. I am not sure why timeout works and pause does not. It's a good fix but I still would love to know what happens with pause. Commented Jun 16, 2014 at 9:45

1 Answer 1

3

:eof is an internal end of file used by CMD and it will exit the routine.

Change it to a different label.

Here is an example to demonstrate the function:

@echo off
echo start
goto :eof
echo this will never appear and pause will not function
pause
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the tip. I changed it by :endplz but it didn't help with the pause problem. Always good to know things like that though!
did you also change every goto :eof ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.