Menu

Looking for a script to mount an USB volume

2020-01-26
2020-01-28
  • Guy Trioreau

    Guy Trioreau - 2020-01-26

    Hi,
    I'm starting with VeraCrypt.
    I would like to write a script allowing to mount an external USB key just executing a .bat module, after a prompt to get the volume password.
    The samples I found are not efficient. Could someone help me ?
    Thanks in advance.
    Guy

     
  • Adrian Kentleton

    How much help do you need? Are you used to creating batch files? Are you familiar with VC command line syntax?
    At its simplest, something like this would do it:

    @echo off
    set /p pwd=Enter Password (in double quotes):
    veracrypt /p %pwd% {your other VC options}
    exit
    
     
  • Guy Trioreau

    Guy Trioreau - 2020-01-27

    Thank you Adrian for your answer.
    I have worked in IT, and think I will not have much problem with batch language, but I don’t manage VeraCrypt options.
    My need is : for people using an USB key encrypted with VeraCrypt, to mount it in a very simple mode, running a batch, and just giving the password, and may be drive letter where the key is plugged.
    (I think they will have to give either the USB key drive letter , or the name of the encrypted container ?).
    So what could be the VC options to use ?

    Thanks in advance.

     
  • Adrian Kentleton

    You should familiarise yourself with the Command Line documentation.

    Something like this should work; test it on non-critical devices first!

    @echo off & :: 2020.01.28
    title Batch File to Mount VeraCrypted USB Key
    ::
    :rerun
    set /p let=Enter drive letter to mount to:
    if not exist %let%:\ goto skip01
    echo That letter is in use
    echo Choose another drive letter
    goto rerun
    ::
    :skip01
    set /p pwd=Enter password (in double quotes):
    ::
    :: Edit op1-op4 to suit your needs and USB key:
    set op1=/q /m rm /c n /h n /m ts
    set op2=/nowaitdlg /m label=Test 
    set op3=/hash sha512
    set op4=/v ID:FBD167B5FAB98B92F327A1BF7900545BD6540A6F34BAEFE9D231FFA2ADB93F9C
    ::
    set op5=/l %let% /p %pwd%
    ::
    veracrypt %op1% %op2% %op3% %op4% %op5%
    ::
    exit
    

    a. The file tests that mounting is not being attempted to a drive letter already in use.
    b. The USB key is identified via its ID, which you can find out by mounting it once manually, right-clicking on its entry in the GUI, and viewing its 'Properties'. Using the ID avoids the USB key itself needing to be mounted to a (known) drive letter.

     

    Last edit: Adrian Kentleton 2020-01-28

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.