DAEMON Tools HOME
DAEMON Tools FORUM

Batch File Example

Create a batch file. Open Notepad and copy the following text:

@echo off
cd /D "%PROGRAMFILES%\DAEMON Tools Pro"

DTAgent.exe -add scsi
if errorlevel 0 goto mount_image
if errorlevel -1 goto error_add

:error_add
echo You couldn't add new virtual drive. Possible, you already have the maximum drives on your system. 

:mount_image
DTAgent.exe -mount scsi, 1, "D:\Images\Games\Tortuga_game\Tortuga_game.mds"

if errorlevel 0 goto get_letter
if errorlevel -1 goto end

:get_letter
DTAgent.exe -get_letter scsi, 1

if errorlevel 0 goto exit_successfull
if errorlevel -1 goto error_letter

:end
echo Image file not found
goto exit


:exit_successfull
echo An image was seccessfully mounted to %errorlevel% letter (A-0, B-1, C-2 etc.) drive.
goto exit


:error_exit
echo Image file not found or drive not added
goto exit

:error_letter
echo Can't define drive letter

:exit
pause

@echo off — will turn off all line echoes in the batch file script.
cd — to change the current working directory. Point to the folder that contains the program which will execute your code. Use the /D switch to change current drive in addition to changing current directory for a drive.
PROGRAMFILES this variable points to Program Files directory, which stores all the installed program of Windows and others. Use variable PROGRAMFILES(x86) for a 64-bit version operating system.
errorlevel — to retrieve the value of the return code.
pause — Suspends processing of a batch program and displays the message "Press any key to continue!", use to view the result of executing. Really convenient being able to pause the running code in end execution.

Save the file with any name, anywhere. Make sure that you have assigned extension *.cmd or *.bat (because the Notepad will assign the default *.txt). Now run your file. If you have already used maximum number of SCSI virtual drive or exist any other reason why program can't add new SCSI drive, you will see the appropriate warning message. Otherwise new SCSI virtual drive will be added to your system and the program tries to mount it. If there is no found mounted image because you have pointed invalid path or name of image, you will see warning message and program will finish. If you have successfully mounted game images on the virtual drive, which is located on the D drive, the program returns the number of letter of the alphabet. If it returns value of 6, it is the letter G, because numbering starts with zero. Please note that the number of new drive is listed as 1, because when you install the program automatically adds a virtual drive that is set to 0, respectively.