View Full Version : BAT file tips

04.03.2012, 16:34
Here's an example for a batch program that works fine in windows 7.

All you have to modify to use the code is the 3 top lines: 1) Location of .mds file to mount; 2) location of DTLite or the standard edition of DT program; 3) location of program to run after mount.

Modify and it should automatically add a scsi drive, mount mds file to it, launch program to run while mounted and after closing that program: remove the drive again!

@echo off

set mds_file="D:\Some Directory\mds\Some Image File.mds"
set DTLite="C:\Program Files (x86)\DAEMON Tools Lite\DTLite.exe"
set Prg_run="D:\Some Directory\Project\Program to run.exe"

IF NOT EXIST %mds_file% goto missing_mds
IF NOT EXIST %DTLite% goto missing_DTLite
IF NOT EXIST %Prg_run% goto missing_PrgToRun
echo MDS location : %mds_file% ok!
echo DTLite location : %DTLite% ok!
echo Program location: %Prg_run% ok!

%DTLite% -get_count scsi
set scsi_count=%errorlevel%
echo Number of scsi virtual drives already: %scsi_count%

echo Adding scsi virtual drive...
%DTLite% -add scsi
if errorlevel 0 goto get_letter
if errorlevel -1 goto error_add

%DTLite% -get_letter scsi, %scsi_count%

if errorlevel 0 goto mount_image
if errorlevel -1 goto error_letter

echo Scsi virtual drive letter %errorlevel% ok!
echo (Drive letter: D=3, E=4, F=5, G=6, H=7, I=8, J=9, K=10, ...)
echo Mounting image...
%DTLite% -mount scsi, %scsi_count%, %mds_file%
if errorlevel 0 goto remove
if errorlevel -1 goto error_mount

echo Mount ok!
echo Running: %Prg_run%


echo Removing used scsi virtual drive...
%DTLite% -remove scsi, %scsi_count%

echo Error: Not found %DTLite%.
goto exit

echo Error: File not found %mds_file%.
goto exit

echo Error: Program to run file not found %Prg_run%.
goto exit

echo Failed to add new scsi virtual drive!
goto exit

echo Could not retrieve scsi virtual drive letter!

echo Error: Unable to mount image file %mds_file%!
goto exit