Automatically open a KeePass database

I'm not sure if this is a new feature or not, but I found a useful thing to do with KeePass. You can use command line switches to specify things like which database to open, and then give it the things it needs to open it, like your password and the location of the keyfile. Having KeePass launch automatically when I log on is very convenient for me. The issue with this is that the shortcut would end up having your database password in it for every who went poking around your computer to see. The latest version of KeePass has an option to encode a password using your Windows account so it will only work on that profile.

To set this up, make a new entry in KeePass for your master password. In the auto-type tab, change the default sequence to {PASSWORD_ENC}. Now, what I did was made a small batch file called keepass.cmd and placed it in my startup folder in the Start Menu. The contents of the file looked like this.

SET DATABASE="C:\path\to\Database.kdbx"
SET KEYFILE="C:\path\to\pwsafe.key"
SET PASSWORD_ENC="blah"
START "" "C:\Program Files\KeePass Password Safe 2\KeePass.exe" %DATABASE% -keyfile:%KEYFILE% -pw-enc:%PASSWORD_ENC%
Put the full path to your database and keyfile in the quotes on the first and second line. For the 3rd line, use auto-type on your master password to add the encoded version of your password, it will be something insane like 350 characters long. Save the Batch file and you can now run it to automatically open your KeePass database. Because of the way the password is encode, it will only work on your current windows account, if you use multiple computers, you'll need to get the unique encoded password for each one and modify the batch file. I'm pretty sure this will only work with version 2.15 or later. Any questions or feedback is always welcome.

5 comments:

AlexHappy said...

GREAT!!!
THANK YOU!

clriis said...

Thanks a lot. I just love simplified explanations to useful hacks

clriis said...

Thanks a lot. I really like simplified explanations to useful hacks.

Anonymous said...

What if you change or lose your Windows user account? I think that your method leads to permant loss of your database

ddaydj said...

@Anonymous, that's right. This script will only work on the computer and user account you set it up on (unless you're on a domain). The script will also stop working if your password is reset by an admin or hack tool.