How can I add Windows Credentials to Credentials Manager on Windows programmatically?
Asked Answered
G

0

8

I have looked at this question's selected answer, Retrieve Credentials from Windows Credentials Store using C#, which uses the CredentialManagement NuGet package to get and set credentials on Windows.

Credential Management package is a wrapper for the Windows Credential Management API that supports both the old and the new style of UI

I was able to set new credentials that way. However, they were set as Generic Credentials.

public static bool SetCredentials(
     string target, string username, string password, PersistanceType persistenceType)
    {
        return new Credential
        {
            Target = target,
            Username = username,
            Password = password,
            PersistanceType = persistenceType
        }.Save();
    }

According to this, there are at least four different types of credentials that the Windows Credentials Manager can use:

  • Windows Credentials
  • Certificate-Based Credentials
  • Generic Credentials
  • Web Credentials

The credentials I need to set are intended to allow access to a specific local web server, and when I have added them manually as Windows Credentials they work, when they get added as Generic Credentials by the application, or myself, they don't work.

Enter image description here

I couldn't find enough information about this here, so how can I add Windows Credentials to the Windows Credentials Manager by using this package, or in any other way that can be done programmatically?

I managed to solve my issue by doing it the way it's shown in this question: C# Using CredWrite to Access C$.

Gaygaya answered 28/2, 2018 at 15:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.