The following command works fine:
"C:\Program Files (x86)\KeePass Password Safe 2\KPScript.exe" -c:GetEntryString "C:\Users\Me\Documents\KeePass Database.kdbx" -useraccount -field:Password -ref-Title:"Data Partition" -FailIfNotExists -FailIfNoEntry
It returns a password out of a KeePass database. In a batch file, I want to put the result of that into a variable, so I can pass it to another program.
I tried the following in a batch file:
@ECHO OFF
SETLOCAL EnableDelayedExpansion
FOR /F "tokens=* usebackq" %%F IN (`"C:\Program Files (x86)\KeePass Password Safe 2\KPScript.exe" -c:GetEntryString "C:\Users\Me\Documents\KeePass Database.kdbx" -useraccount -field:Password -ref-Title:"Data Partition" -FailIfNotExists -FailIfNoEntry`) DO SET pw=%%F
ECHO %pw%
ENDLOCAL
But calling this batch file returns:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
I tried putting quotes around the command in FOR:
@ECHO OFF
SETLOCAL EnableDelayedExpansion
FOR /F "tokens=* usebackq" %%F IN (`""C:\Program Files (x86)\KeePass Password Safe 2\KPScript.exe" -c:GetEntryString "C:\Users\Me\Documents\KeePass Database.kdbx" -useraccount -field:Password -ref-Title:"Data Partition" -FailIfNotExists -FailIfNoEntry"`) DO SET pw=%%F
ECHO %pw%
ENDLOCAL
And this time I got:
\KeePass was unexpected at this time.
What is the correct syntax to make this work? Thanks.