0

I am new to stackoverflow and C#. I recently started to publish simple WinForm apps but I still have a long way to go...

I wrote an app that uses the above nuget package to remove all credentials stored locally.

I am able to use CredentialManager.RemoveCredentials() method to remove Type: Generic credentials.

But I cannot remove Generic Certificate and Domain Password credential types. it throws a generic exception saying that the credentials cannot be deleted. As I said I am new to c#, am I missing something?

Thanks in advance

Angelo

enter image description here

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107

1 Answers1

0

I know this is little late to answer this question but it is still unanswered so thought of providing a solution.

CredentialManager.RemoveCredentials()

Will not work if you are storing the credentials as LocalMachine (cred1.Persistance = Persistance.LocalMachine; or you are not at all providing Persistance attribute while storing the credentials) as CredentialManager.RemoveCredentials() deletes credentials if Persistance is set to Enterprise.

Hence the problem is not with your removal logic but it is with creation logic.

Create the credentials with below code :

var cred1 = (new NetworkCredential("UserName", "PassWord")).ToICredential();
            cred1.TargetName = "TargetName";
            cred1.Attributes = new Dictionary<string, Object>();
            cred1.Persistance = Persistance.Enterprise;
            cred1.SaveCredential();

and For Removal just use below:

CredentialManager.RemoveCredentials("TargetName");

If it doesn't work please post your creation logic also, so I can verify.

Mayank Tripathi
  • 809
  • 1
  • 7
  • 11