I found a great article about a script to mount a TrueCrypt Volume on Windows here. Â It also detailed a script to unmount the volume.
I decided to improve on it a bit, and allow the same script to mount and unmount the volume (by testing to see if the volume is mounted). Â I did not include his password parameter because TrueCrypt will ask for the password anyway. And I really don’t want to code my password into any script.
So here is the script:
REM TrueCrypt mounting script (version 2)
REM Based on script Written by Mark Ursino (allthingsmarked.com)
REM Modified by Zen (Zenmojo.com)
REM Modifications are allowed, but please include these comments
@echo offset TrueSource=I:\TrueCrypt\truecrypt
set Source=I:\volume.cab
set Drive=O:IF EXIST “%Drive%” goto unmount
:mount
cls
“%TrueSource%” /v “%Source%” /l “%Drive%” /m /a /p /q
explorer.exe “%Drive%”
cls
goto end:unmount
cls
“%TrueSource%” /d”%Drive%” /q
cls
goto end:end
cls
Notes:
TrueSource is the location of your truecrypt.sys file (from the stand-alone version of TrueCrypt)
Source is the source of your TrueCrypt file
Drive is the drive letter you want to mount the file to
September 25th, 2009 at 6:53 am
Your site was extremely interesting, especially since I was searching for thoughts on this subject last Thursday.
July 27th, 2011 at 6:13 pm
Your script didn’t work for me on Win7 64-bit until I deleted the quotation marks from around the variables. Took me a while to figure it out, but now it works like a charm!
Now if I can only figure out how to keep the Command Prompt window invisible while using a program in the TrueCrypt volume as a blocking mechanism (i.e. no “start” command to make it run in the background). Ergo, when I close the program, the volume is automatically unmounted, but until then the Command Prompt window stays in the taskbar.
July 28th, 2011 at 9:05 am
Jeff, thanks for the tip on Windows 7. I hadn’t tried it on 7 yet.
Sounds like you would need to use something that supports an “on_close” parameter to run the unmount section when the window is closed.
May 25th, 2012 at 7:33 am
set Source=\TrueCrypt\Crypted!
set Drive=O:
set tDrive=%cd:~0,3%
if EXIST “C:\Program Files\TrueCrypt\TrueCrypt.exe” (
C:
cd C:\Program Files\TrueCrypt
) ELSE (
cd \TrueCrypt
)
TrueCrypt /v “%tDrive%\TrueCrypt\Crypted!” /l “%Drive%” /m /a /p
May 25th, 2012 at 7:38 am
Thanks. I run this script on multiple computers with or witnout installed TrueCrypt. Attempt to run Truecrypt version which differs would cause error.
November 27th, 2012 at 4:30 am
Does anyone know how to do this with keyfiles/keymaps?
December 3rd, 2012 at 9:29 am
Look to truecrypt site on command line
for ex: truecrypt /lw /v VOL /k bitmap.bmp /a /p “password” /m rm /e /q
volume TC = VOL
keyfile = bitmap.bmp
Disq = W in removable
open explorer on disq