带有批处理文件的Veracrypt:如果未挂载驱动器,如何停止执行?



我有一个简单的批处理文件,它首先启动veracrypt,然后挂载另一个批处理文件:

C:
cd C:Program2VeraCrypt
veracrypt /v DeviceHarddisk2Partition1 /l L /a /p 123xyz /q 
cd /D D:backup
start_backup.bat

start_backup.bat使用robocopy(Windows 10(启动备份,该备份将文件从一个驱动器C更新/复制到外部加密硬盘驱动器D,分别是L(挂载名称(。

如果 veracrypt 由于任何原因(例如没有驱动器(无法挂载驱动器,则批处理start_backup.bat将在没有备份的情况下启动,因为无法访问加密驱动器。在无法安装驱动器的情况下,如何避免start_backup.bat启动?

批处理文件是使用 cmd.exe 命令编写的。

执行此操作的简单方法是使用运算符:&&||...


@echo off && setlocal EnableDelayedExpansion
cd /d "C:Program2VeraCrypt"
(
.veracrypt.exe /v DeviceHarddisk2Partition1 /l L /a /p 123xyz /q 
) && (
cd /D "D:backup" & call start_backup.bat
) || (
echo/ something really wrong is going on here....
%__APPDIR__%timeout.exe -1
goto :EOF
) 
rem ::  continue with more task here.... or goto :EOF

  • 或。。。
@echo off && setlocal EnableDelayedExpansion
cd /d "C:Program2VeraCrypt"
.veracrypt.exe /v DeviceHarddisk2Partition1 /l L /a /p 123xyz /q  && (
cd /D "D:backup" & call start_backup.bat ) || (
echo/ Something really wrong is going on here....
%__APPDIR__%timeout.exe -1 & goto :EOF ) 
rem ::  continue with more task here.... or goto :EOF

  • 可选择进行三次尝试,超时时间为 30 秒
@echo off && setlocal EnableDelayedExpansion
cd /d "C:Program2VeraCrypt"
:loop
set /a "_cnt+=1+0"
(
.veracrypt.exe /v DeviceHarddisk2Partition1 /l L /a /p 123xyz /q 
) && (
cd /D "D:backup" & call start_backup.bat
) || (
echo/ something really wrong is going on here....
if "!_cnt!"=="3" (
echo/ Some is really wrong here....
%__APPDIR__%timeout.exe -1 & goto :EOF 
) else (
echo/ Let's try +1 times until 3 [!_cnt!/10]
%__APPDIR__%timeout.exe 30 
goto :loop
)
) 

  • 选择按照@Stephan的建议使用if !errorlevel! 0/1 else进行三次尝试,超时时间为 30 秒...
@echo off && setlocal EnableDelayedExpansion
cd /d "C:Program2VeraCrypt"
:loop
set /a "_cnt+=1+0" && type nul>nul
.veracrypt.exe /v DeviceHarddisk2Partition1 /l L /a /p 123xyz /q 
if !errorlevel! == 0 (
cd /D "D:backup" & call start_backup.bat
) else (
echo/ Something really wrong is going on here....
if "!_cnt!"=="4" (
echo/ Some is really wrong here....
%__APPDIR__%timeout.exe -1 & goto :EOF 
) else (
echo/ Let's try +1 times until 03 [0!_cnt!/03]
%__APPDIR__%timeout.exe 30 
goto :loop
)
) 

goto eof返回哪里

bat/cmd中的运算符/语法重定向

最新更新