10

We can remove remembered/cached passwords via Credential Manager as here and via a command cmdkey as here.

I want to have one command that quickly clear all the passwords. How can we do that?

Nam G VU
  • 12,146
  • 60
  • 135
  • 209

3 Answers3

19

for that, you sure need to create a batch file. maybe follwing link will help you on this

This is the similar post. Try it out.

The script

cmdkey.exe /list > "%TEMP%\List.txt"
findstr.exe Target "%TEMP%\List.txt" > "%TEMP%\tokensonly.txt"
FOR /F "tokens=1,2 delims= " %%G IN (%TEMP%\tokensonly.txt) DO cmdkey.exe /delete:%%H
del "%TEMP%\List.txt" /s /f /q
del "%TEMP%\tokensonly.txt" /s /f /q
Arvo Bowen
  • 486
  • 3
  • 9
  • 26
Kirk
  • 1,433
  • 11
  • 14
  • 1
    When I run this as administrator, I get: `Hdel was unexpected at this time` - what does that mean? – bgmCoder Oct 15 '18 at 15:53
11

Try the following one-liner:

for /F "tokens=1,2 delims= " %G in ('cmdkey /list ^| findstr Target') do  cmdkey /delete %H

It does exactly what the batch file does, but without the temporary files, and in a single line. Pipe the results of the cmdkey /list into findstr (which will search for a string from STDIN). Then use the result inside of a FOR loop using it's single quote "command to process" feature, and, deleting each of the items (the second parameter in the list) A nifty way to do the same thing as the batch file using just standard piping, and no temporary files.

gcc
  • 119
  • 1
  • 2
  • Can you explain what this command does? It has been flagged for removal as it lacks context. Please see [answer] and take our [tour]. – Burgi Oct 21 '16 at 22:04
  • It does exactly what the batch file does, but without the temporary files, and in a single line. Pipe the results of the cmdkey /list into findstr (which will search for a string from STDIN). Then use the result inside of a FOR loop using it's single quote "command to process" feature, and, deleting each of the items (the second parameter in the list) A nifty way to do the same thing as the batch file using just standard piping, and no temporary files. – gcc Oct 21 '16 at 23:30
  • 2
    You should [edit] your answer to include that information... – Burgi Oct 22 '16 at 00:20
  • Works like a charm! – bgmCoder Mar 09 '18 at 16:40
  • Worked great. Note FINDSTR is cAsE sEnSiTivE by default. Example Outlook flush usage: ('cmdkey /list ^| findstr /i office') but note it would also match a logon like 'securityofficer@org' so you may want to be more specific. – WhoIsRich May 31 '18 at 14:53
  • What syntax can we use to search for and delete strings with a space like "my office"? Does this command search everywhere in the returned text, like the 'target', the 'username' and so on? – PeterCo May 21 '21 at 14:06
2

Sure, but it depends on how many 'targetnames' you have.

cmdkey /delete:Administrator && cmdkey /delete:Knuckle-Dragger
Knuckle-Dragger
  • 2,043
  • 1
  • 14
  • 19