问题
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 4 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.
I couldn't find enough information about this here, so what I need to know is how to add Windows Credentials to the Windows Credentials Manager by using this package, or in any other way that can be done programmatically.
UPDATE: I managed to solve my issue by doing it the way it's shown on this question: C# Using CredWrite to Access C$. However, since I didn't want to answer the same thing here as well, I will leave the question open in case someone knows how to do it differently, or else I will vote to close it.
UPDATE 2: Although by the time the previous update was posted the solution that was found then was working, it's not working now. So I'm still looking for a way to completely solve this problem. I'm sure the previous link can still be useful for someone else though.
来源:https://stackoverflow.com/questions/49033193/how-to-add-windows-credentials-to-credentials-manager-on-windows-programmaticall