nolags
nolags

Reputation: 633

can't continue script from .bat file after closing msgbox

I have a script that saves 2 files in a backup folder. I want to get a message box if the copy command was successful or not.

@echo off
Echo msgbox"Saving test1 to \backup directory." + vbNewLine + "Successfull!",0,"Backup file..">test1.vbs
Echo msgbox"Saving test2 to \backup directory." + vbNewLine + "Successfull!",0,"Backup file..">test2.vbs

copy test1.txt backup\test1.txt
if %ERRORLEVEL% == 0 (
    start test1.vbs
    goto test2
)else (
    echo ## Errorausgabe: %ERRORLEVEL%
    echo.
)

:test2
copy test2.txt backup\test2.txt
if %ERRORLEVEL% == 0(
    start test2.vbs
    goto commonexit
)else(
echo ## Errorausgabe: %ERRORLEVEL%
)

:commonexit
pause

It works till i get the message box from test1. But when I click submit the test2 doesnt start. What's the problem here?

Upvotes: 1

Views: 56

Answers (2)

nolags
nolags

Reputation: 633

The Problem was he couldn't find the tes2.vbs file. added %tmp%\ as directory path for the vbs files! Now it works.

Upvotes: 0

Hackoo
Hackoo

Reputation: 18837

In this line you omit a space if %ERRORLEVEL% == 0( should be if %ERRORLEVEL% == 0 ( and in this line too )else ( should be ) else (

Try like this :

@echo off
Echo msgbox"Saving test1 to \backup directory." + vbNewLine + "Successfull!",0,"Backup file..">test1.vbs
Echo msgbox"Saving test2 to \backup directory." + vbNewLine + "Successfull!",0,"Backup file..">test2.vbs

copy test1.txt backup\test1.txt
if "%ERRORLEVEL%" EQU "0" (
    start test1.vbs
    goto test2
) else (
    echo ## Errorausgabe: %ERRORLEVEL%
    echo.
)

:test2
copy test2.txt backup\test2.txt
if "%ERRORLEVEL%" EQU "0" (
    start test2.vbs
    goto commonexit
) else (
echo ## Errorausgabe: %ERRORLEVEL%
)

:commonexit
pause

https://ss64.com/nt/if.html

Upvotes: 2

Related Questions