If you use KeePass to manage your passwords, you can securely automate database unlocking at boot or login using the {PASSWORD_ENC} placeholder. This guide combines best practices, official documentation, and user insights, and now also explains how to set up your script to run automatically from the Windows Startup folder. Additionally, it details how KeePass’s Auto-Type feature works, including window title matching for automatic credential filling.

Why Use {PASSWORD_ENC}?

KeePass’s {PASSWORD_ENC} placeholder generates a unique, encrypted master password string, valid only for your current Windows user and computer. This encrypted string can be safely stored in scripts or batch files, as it cannot be reused on another system or account.

Why Not Just Use Windows Login in KeePass?#

Although KeePass 2.x allows you to use your Windows user account as part of the master key, this approach has significant drawbacks:

  • Risk of Data Loss: If your Windows user profile (SID/UID) becomes corrupt or is deleted, you will lose access to your KeePass database permanently. Creating a new Windows account with the same username and password is not sufficient, as the underlying security identifier (SID) will be different.
  • Synchronization Issues: If you want to synchronize your KeePass database across multiple devices or users, you cannot use the Windows user account option, as the encrypted database will only open for the original Windows account on the original machine[^1][^2].
  • Backup and Recovery Complexity: Restoring access requires complex procedures, such as backing up and restoring the exact Windows user account or DPAPI keys, which is not straightforward and can be risky for most users.

Because of these limitations, relying solely on Windows login for KeePass database protection is discouraged, especially for users who need portability, synchronization, or reliable backup and recovery. The {PASSWORD_ENC} method offers a secure alternative—enabling automation without sacrificing database accessibility or security

Step-by-Step Guide#

1. Create Your Batch Script

  • Open Notepad and create a new file, e.g., RunMeKeePass.bat.

2. Prepare a Temporary Entry in KeePass

  • Open your KeePass database.
  • Create a new, temporary entry (e.g., “RunMeKeePass.bat”).

3. Configure Auto-Type with {PASSWORD_ENC}

  • Go to the “Auto-Type” tab of your new entry.
  • Select the “Override default sequence” radio button.
  • In the field, enter {PASSWORD_ENC}.
  • Important: In the password field of this entry, you must enter your actual KeePass master password. The {PASSWORD_ENC} placeholder uses this to generate the encrypted string.

KeePass

4. Generate the Encrypted Password String

  • With KeePass open and your batch file in Notepad, focus on Notepad and press Ctrl+Alt+A (or your configured Auto-Type hotkey).
  • KeePass will auto-type a long, encrypted string into Notepad. This is your {PASSWORD_ENC} value.
  • Copy and securely save this string. It will only work for your Windows user on this machine.

5. Edit Your Batch File

Insert the following lines, adjusting paths as needed:

SET DATABASE="%USERPROFILE%\Documents\<PATH_TO_YOUR_DATABASE>.kdbx"
SET PASSWORD_ENC="<PASTE_YOUR_ENCRYPTED_STRING_HERE>"
START "" "%ProgramFiles(x86)%\KeePass Password Safe 2\KeePass.exe" %DATABASE% -pw-enc:%PASSWORD_ENC%
TIMEOUT 2
  • If you use a keyfile, add:
SET KEYFILE="%USERPROFILE%\Documents\<PATH_TO_YOUR_KEYFILE>"
START "" "%ProgramFiles(x86)%\KeePass Password Safe 2\KeePass.exe" %DATABASE% -keyfile:%KEYFILE% -pw-enc:%PASSWORD_ENC%

6. Automate Launch at Boot/Login

  • You can use Windows Task Scheduler to run your batch file at logon.
  • Or: Save your batch file into the Windows Startup folder. To open this folder, press Win + R, type shell:startup, and press Enter. Copy your batch file into this folder. The script will now run automatically each time you log in.

How Auto-Type Works in KeePass#

KeePass’s Auto-Type feature allows you to automatically fill in login forms in applications and websites. It works by simulating keystrokes to the currently active window. You can configure Auto-Type for each entry, specifying:

  • The sequence of keystrokes (e.g., {USERNAME}{TAB}{PASSWORD}{ENTER}).
  • The target window based on its title.

KeePass matches the window title of the active application against the window associations defined in your entry. You can use wildcards or regular expressions to match multiple windows (for example, * - Mozilla Firefox will match any tab in Firefox). When you trigger Auto-Type (default hotkey: Ctrl+Alt+A), KeePass searches for entries with a matching window association and executes the defined sequence, filling in your credentials automatically.

Example Auto-Type Sequence:

{USERNAME}{TAB}{PASSWORD}{ENTER}

This sequence enters your username, presses Tab, enters your password, and presses Enter.

Defining Window Associations:

  • In the entry’s Auto-Type settings, you can add window associations.
  • For example, to target a browser login page, set the window association to * - Google Chrome.
  • KeePass will only use this entry’s Auto-Type sequence when the active window’s title matches the association.

This approach ensures that the right credentials are filled into the right application or website, increasing both security and convenience.

Summary Table#

Step Action Key Detail
1 Create batch file Name it RunMeKeePass.bat
2 Add temp KeePass entry Name as you wish
3 Set Auto-Type to {PASSWORD_ENC} Enter your master password in the entry’s password field
4 Generate encrypted string Use Auto-Type hotkey
5 Edit batch file Insert paths and encrypted string
6 Automate startup Use Task Scheduler or copy the batch file to shell:startup

By following these steps, you can securely automate KeePass database unlocking at boot or login and take advantage of KeePass’s powerful Auto-Type feature for seamless, context-aware credential filling.

http://keepass.info/help/base/autotype.html

https://www.kutac.cz/pocitace-a-internety/keepass-a-automaticke-doplnovani-formularu

https://www.tyflokabinet.cz/clanky/tecko/keepass

https://www.zive.cz/clanky/automaticke-vyplnovani-ve-spravci-hesel-byste-si-meli-vypnout-hrozi-unik-dat/sc-3-a-211608/default.aspx

https://www.michalzobec.cz/keepass-konfigurace-samodoplnovani-za-pomoci-klavesove-zkratky-3256

https://radja.cz/41/nastaveni-auto-type-sekvence-ve-spravci-hesel-keepass-aneb-automaticke-vyplnovani-hesel/

https://tyflokabinet.cz/node/135

https://www.zive.cz/clanky/keepass-password-safe-hesla-jako-v-sejfu/sc-3-a-147400/default.aspx?showforum=1

https://www.youtube.com/watch?v=AOFF66BMtxk

https://www.reddit.com/r/KeePass/comments/1ga90uh/keepass_vs_keepassxc_whats_actually_better_for/?tl=cs

https://geekblog.cz/keepass-pro-iphone-jak-pouzivat-keepass-na-ios/