2017-09-20 170 views
1

我有一個腳本將2個文件保存在備份文件夾中。如果複製命令成功,我想獲得一個消息框。關閉後無法從.bat文件繼續執行腳本msgbox

@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 

它的工作,直到我從test1消息框。但是當我點擊提交時,test2不會啓動。這裏有什麼問題?

回答

2

在這一行你省略了一個空間if %ERRORLEVEL% == 0(if %ERRORLEVEL% == 0 (並在這一行太)else (應該) else (

嘗試這樣的:

@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

+0

它複製兩個,但不顯示msgbox! – nolags

+1

@nolags請再次檢查我編輯我的答案,我測試它的MsgBox顯示爲我! – Hackoo

+0

它在vbscript中打印兼容性問題..他正在等待命令完成test2.vbs – nolags

0

的問題是,他couldn」找到tes2.vbs文件。添加%tmp%\作爲vbs文件的目錄路徑!現在它可以工作。

相關問題