Scheduling Programs to start only when an Encrypted File System is mounted (on Windows)

I am running an email client, although I want the database to be stored in an encrypted directory. Using task scheduler I can auto start the email client, only once the encrypted container is mounted.

Running programs from an encrypted file system enhances data security but can pose challenges when executing programs reliant on files within the encrypted system. This article presents a practical solution using a batch script to automate execution only when the encrypted file system is successfully mounted. By retrying at intervals, the script ensures smooth execution without compromising security.

ChatGPT

I was having trouble with this script not disappearing once the program started, as in the previous article. I enhanced it further by adding a component to retry if not mounted as follows.

The following batch file is called by task scheduler when logged in:

@echo off

set "secondBatchFile=Path\to\second_batch_file.bat"
set "retryInterval=60"

:retry
if exist "%secondBatchFile%" (
    echo Second batch file found. Starting...
    call "%secondBatchFile%"
    echo Second batch file execution completed.
    timeout /t 3 >nul
    exit
) else (
    echo Cannot start email client yet. Retrying in %retryInterval% seconds...
    timeout /t %retryInterval% >nul
    goto retry
)

The second batch file is as follows:

@echo off
start "" /B "C:\Program Files (x86)\eM Client\MailClient.exe"
exit

Easy 🙂

Scroll to Top