'How can I add Windows Credentials to Credentials Manager on Windows programmatically?

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$.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source