Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Batch file to clear all credentials from Windows Credential Manager
@echo off
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
echo All done
pause
@ion-storm

This comment has been minimized.

Copy link

@ion-storm ion-storm commented Jan 5, 2017

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

@ukmercenary

This comment has been minimized.

Copy link

@ukmercenary ukmercenary commented May 2, 2019

Works great thanks alot!

@memehunter

This comment has been minimized.

Copy link

@memehunter memehunter commented Jun 4, 2019

thank you :)

@loosetile2

This comment has been minimized.

Copy link

@loosetile2 loosetile2 commented Oct 23, 2019

This works the finest. Thank you.
Just a quick one, if i run this from a command promt or called from another script, how do I make sure it's the logged in user that this runs for and not administrator. For example, using LogMeIn I may be logged into a users PC and when I run this, it gets run as an admin not as the user. Is there a way i can make sure the script runs as the....let's say currently active user rather than as administrator?

@tomfanning

This comment has been minimized.

Copy link
Owner Author

@tomfanning tomfanning commented Oct 23, 2019

@MarJone

This comment has been minimized.

Copy link

@MarJone MarJone commented Nov 19, 2019

Thanks for this. is there a way to only delete credentials from a specific source, say Adobe for example, using this script?

@vbargl

This comment has been minimized.

Copy link

@vbargl vbargl commented Mar 21, 2020

For keys which have space in name you can use tokens=1,* delims= instead

@jcalado

This comment has been minimized.

Copy link

@jcalado jcalado commented Apr 3, 2020

Thanks for this. is there a way to only delete credentials from a specific source, say Adobe for example, using this script?

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

This worked for me!

@BarisUygun

This comment has been minimized.

Copy link

@BarisUygun BarisUygun commented Apr 13, 2020

  • I am trying to execute this on wix toolset. The batch file executes but the output is this:

  • Deleted file - D:\Users\xx\AppData\Local\Temp\List.txt
    -Deleted file - D:\Users\xx\AppData\Local\Temp\tokensonly.txt
    -All done
    -Press any key to continue . . .

-Normally output should be like:

  • CMDKEY: Credential deleted successfully.
    -CMDKEY: Credential deleted successfully.
    -Deleted file - D:\Users\xx\AppData\Local\Temp\List.txt
    -Deleted file - D:\Users\xx\AppData\Local\Temp\tokensonly.txt
    -All done
    -Press any key to continue . . .

-Can you think of any reason why this could happen? The credentials do not get deleted when i execute batch on wix toolset

@classworks

This comment has been minimized.

Copy link

@classworks classworks commented May 6, 2020

Is it able to remove Google chrome, Firefox credential ? If not please, Help me how can I remove Google chrome, Firefox credential.
Kind regards

@BarisUygun

This comment has been minimized.

Copy link

@BarisUygun BarisUygun commented May 6, 2020

@classworks Are you trying to delete them with a batch? If so
@echo off cmdkey.exe /list > "%TEMP%\List.txt" findstr.exe Target "%TEMP%\List.txt" > "%TEMP%\tokensonly.txt" for /F "tokens=1,* delims= " %G in ('cmdkey /list ^| findstr !THE CHROME OR FIREFOX CREDENTIAL NAME!') do cmdkey /delete %H del "%TEMP%\List.txt" /s /f /q del "%TEMP%\tokensonly.txt" /s /f /q echo All done pause
Something like this should work.

@classworks

This comment has been minimized.

Copy link

@classworks classworks commented May 8, 2020

@BarisUygun
I have tried this for Google chrome
@echo off
set ChromeDir=C:\Users%USERNAME%\AppData\Local\Google\Chrome\User Data
del /q /s /f "%ChromeDir%"
rd /s /q "%ChromeDir%"

******For Mozilla firefox
@echo off
set DataDir=C:\Users%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles
del /q /s /f "%DataDir%"
rd /s /q "%DataDir%"
for /d %%x in (C:\Users%USERNAME%\AppData\Roaming\Mozilla\Firefox\Profiles*) do del /q /s /f %%x*sqlite

**** And For opera
@echo off
set DataDir=C:\Users%USERNAME%\AppData\Local\Opera\Opera
set DataDir2=C:\Users%USERNAME%\AppData\Roaming\Opera\Opera
del /q /s /f "%DataDir%"
rd /s /q "%DataDir%"
del /q /s /f "%DataDir2%"
rd /s /q "%DataDir2%"

But only Google Chrome works when browser remain closed and I execute more than 2 times :(

I am not expert please,Help me to do this in right way.
I want to delete all saved cookies and Passwords

Thanks for your Attention

@BarisUygun

This comment has been minimized.

Copy link

@BarisUygun BarisUygun commented May 8, 2020

I am not an expert too. But this can delete credentials under windows credential store i don't know if you can delete browser credentials.

@echo off
cmdkey.exe /list > "%TEMP%\List.txt"
findstr.exe Target "%TEMP%\List.txt" > "%TEMP%\tokensonly.txt"
for /F "tokens=1,* delims= " %G in ('cmdkey /list ^| findstr Adobe') do cmdkey /delete %H
del "%TEMP%\List.txt" /s /f /q
del "%TEMP%\tokensonly.txt" /s /f /q
echo All done
pause

@bharatuow

This comment has been minimized.

Copy link

@bharatuow bharatuow commented May 29, 2020

Thanks for this. is there a way to only delete credentials from a specific source, say Adobe for example, using this script?

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

This worked for me!

Not working for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment