TrueCrypt: Using batch scripts to mount and dismount volumes

Tested on 27 September 2012 using version 7.1a on Windows XP and Windows 7
Note: If you have not yet used or setup a TrueCrypt volume, see TrueCrypt: Encrypting a drive.

Using a batch file to mount or dismount a volume is useful for automating many of the steps needed when using the TrueCrypt application. It also does not require the application to start in the notification area.

First, copy the required TrueCrypt files to the same directory as the encrypted volume:

  • truecrypt.sys is a system file for 32-bit systems
  • truecrypt-x64.sys is a system file for 64-bit systems
  • TrueCrypt.exe is required to mount the virtual drive
  • TrueCrypt Format.exe is only required if you want to create a new volume (virtual drive)
  • A Configuration.xml file will be created after you first run TrueCrypt - this will store any custom settings

Next create a batch file from one of the options below. The file can be created in notepad but should be saved as a .bat extension, not .txt. Insert the text into the file and then save the file into the same directory as the encrypted volume.

Batch file examples:

A simple batch script to mount a hard disk drive as a local disk:

Volume mounted to 'x' in this case

TrueCrypt /v myvolume.tc /lx /a /e /q

A simple batch script to mount a USB drive as a removable disk:

Volume mounted to 'x' in this case

TrueCrypt /v myvolume.tc /lx /m rm /a /e /q

A simple batch script to dismount an encrypted volume:

Volume currently mounted on 'x' in this case

TrueCrypt /q /dx

A simple batch script to dismount all encrypted volumes:

TrueCrypt /q /d

Command switches:

The above examples are where:

  • TrueCrypt: runs the TrueCrypt.exe application
  • /v myvolume.tc: finds the encrypted volume
  • /lx: mounts the volume to drive 'x' (any drive letter not in use can be specified)
  • /a: is implicit if /v is specified
  • /e: opens an Explorer window after mount
  • /q: stops the main TrueCrypt window from being opened
  • /m rm: mounts the volume as a removable medium (required for USB)
  • /dx: dismounts the drive specified - 'x' in this case (if left blank all encrypted drives are dismounted)

A batch script with all options to mount and dismount volumes:

  • @echo off
  • title Mounting and Dismounting TrueCrypt volumes

  • :options
  • cls
  • echo.
  • echo Please choose an option:
  • echo.
  • echo  1: Mount a TrueCrypt volume (as Removable Disk)
  • echo.
  • echo  2: Mount a TrueCrypt volume (as Local Disk)
  • echo.
  • echo  3: Dismount a single TrueCrypt volume
  • echo.
  • echo  4: Dismount all TrueCrypt volumes
  • echo.
  • echo  5: Do nothing (Exit)...
  • echo.
  • set key=0
  • set /p key=:
  • if '%key%'=='1' goto :opt1
  • if '%key%'=='2' goto :opt2
  • if '%key%'=='3' goto :opt3
  • if '%key%'=='4' goto :opt4
  • if '%key%'=='5' goto :opt5
  • echo.
  • echo Invalid choice
  • goto :options

  • :opt1
  • :opt2
  • cls
  • echo.
  • echo Choose a free drive letter to mount the volume...
  • echo.
  • echo Note: The following drives are currently in use:
  • FSUTIL fsinfo drives
  • echo.
  • echo.
  • set /p letter=Enter a drive letter NOT in use:
  • echo.
  • echo.
  • set /p volume=Enter the name of the volume to be mounted:
  • echo.
  • echo.
  • echo Mounting volume...
  • if '%key%'=='1' start %~dp0TrueCrypt /v %~dp0%volume% /l%letter% /m rm /a /e /q
  • if '%key%'=='2' start %~dp0TrueCrypt /v %~dp0%volume% /l%letter% /a /e /q
  • exit

  • :opt3
  • cls
  • echo.
  • set /p dismount=Enter a drive letter to dismount:
  • echo.
  • echo.
  • echo Dismounting...
  • start %~dp0TrueCrypt /q /d%dismount%
  • exit

  • :opt4
  • cls
  • echo.
  • echo Dismounting...
  • start %~dp0TrueCrypt /q /d
  • exit

  • :opt5
  • exit

Go back to the How-to Guides main page.

^ Top of page ^ | Home | Contact | Site map | Copyright © 2014 Fourwest Media. All rights reserved

Valid XHTML 1.0 Strict Valid CSS!