(I answer my own question):
I can find no way to configure KeePass itself to Prompt for master password when restored, so here is a workaround based on this superuser question:
Create and save a new Windows Scheduled Task:
- Start Task Scheduler: Win→Administrative
Tools→Task Scheduler, or Win+R and enter
taskschd.msc
- In Task Scheduler, Action→Create Task
- In Create Task's General tab, name the task Run KeePass at unlock
- In Create Task's Triggers tab, click New... then for Begin the task: select On
workstation unlock and click OK
- In Create Task's Actions tab, click New... then in the Program/script field enter
"C:\WINDOWS\System32\cmd.exe"
and in the Add arguments (optional) field enter /c start "" <location of your KeePass database file>
(the location of your KeePass database file appears in KeePass' main window title).
- Click OK in Create Task to save the task, then close the Task Scheduler window.
Now when you unlock your system, Task Scheduler will execute KeePass, which will gain focus and prompt you for your Master Password. If you have KeePass configured to Minimize main window after opening a database (under Options→Interface), your KeePass windows will also minimize after you have successfully entered your Master Password.
3Out of curiosity, is there a reason why you can't enter the path to KeePass in the Program/script field directly, instead of as an argument to
cmd.exe
? – Kodos Johnson – 2019-01-12T01:59:31.667@KodosJohnson, initially I entered the path as you describe. That caused KeePass to prompt me when I restored my Windows, but KeePass' prompt did not have focus, so I needed to click on the Master Password input field before typing. The use of
cmd.exe
eliminates this need. – CODE-REaD – 2019-01-12T16:35:39.767Perhaps this could be of use to you: https://stackoverflow.com/questions/35988863/using-command-line-batch-to-switch-to-focus-on-app. Also, maybe you need to add a delay somehow in the scheduled task.
– Kodos Johnson – 2019-01-18T17:07:28.813@KodosJohnson, thank you. I considered sendKeys.bat but want to keep this solution as simple as possible. The latest revision (pointing
start
to the location of my KeePass database) seems to work reliably so I've updated my answer with it. Please let me know if there are any problems with this approach. – CODE-REaD – 2019-01-19T14:44:37.820