:: Name : bitlockervdisk.bat
:: Purpose : Create virtual container to store files and bitlock it. Much like truecrypt encrypted file container
:: Author : ZF
@echo OFF
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
::1024 = 1GB
set "SIZE=128"
set "MOUNTDRIVE=q"
::Create disk partition
echo create vdisk file="%CD%\container.vhd" maximum=%SIZE% type=fixed > diskpartcommands.txt
echo select vdisk file="%CD%\container.vhd" >> diskpartcommands.txt
echo attach vdisk >> diskpartcommands.txt
echo create partition primary >> diskpartcommands.txt
echo select partition 1 >> diskpartcommands.txt
echo format fs=ntfs quick label="bitlockedcontainer" >> diskpartcommands.txt
echo active >> diskpartcommands.txt
echo assign letter=%MOUNTDRIVE% >> diskpartcommands.txt
echo exit >> diskpartcommands.txt
diskpart /s %CD%\diskpartcommands.txt > %fullstamp%-log.txt
del %CD%\diskpartcommands.txt
::Fails with message "ERROR: An error occurred (code 0x8031002c):"
::manage-bde -on %MOUNTDRIVE%: -Password
::Eject and mount using explorer.exe
bitlockervdisk.bat (1.27 KB)