我查看了这个问题的选择答案 Retrieve Credentials from Windows Credentials Store using C# ,它使用CredentialManagement NuGet 包在 Windows 上获取和设置凭据。
凭据管理包是 Windows 凭据管理 API 的包装器,它支持新旧样式的 UI
我能够以这种方式设置新凭据,但是它们被设置为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();
}
据此, Windows 凭据管理器可以使用至少 4 种不同类型的凭据:
- Windows 凭据
- 基于证书的凭证
- 通用凭证
- 网络凭证
我需要设置的凭据旨在允许访问特定的本地 Web 服务器,当我手动将它们添加为Windows 凭据时,它们可以工作,当它们被应用程序或我自己添加为通用凭据时,它们不起作用.
我在这里找不到足够的信息,所以我需要知道的是如何通过使用此包或以任何其他可以以编程方式完成的方式将 Windows 凭据添加到 Windows 凭据管理器。
更新:我设法通过在这个问题上显示的方式解决我的问题:C# Using CredWrite to Access C$。但是,由于我也不想在这里回答同样的问题,所以我会留下这个问题,以防有人知道如何以不同的方式做,否则我会投票关闭它。
更新 2:虽然在发布上一个更新时,找到的解决方案正在运行,但现在无法运行。所以我还在寻找彻底解决这个问题的方法。我确信之前的链接仍然对其他人有用。