I simply want to query the Credentials Store (or Vault as it is called in Win8) and get the login data. The MSDN is really unhelpful in this case and I also do not want any C++ pInvoke approaches.
I know that similar questions have been asked here a few times, but none of those solutions work in my case. I do not use Metro App programming so things like PasswordVault
are (as it looks) not available. I just create a simple C# WPF Desktop application.
Ideally it should work in several Windows versions, but Win8 is prefered.
More specifically I want to query the stored data from the CRM plugin for Outlook to automatically have my app log in to the CRM Server without having the User to ask for his Credentials. That means, if this is even possible...
So how do I access the Windows Credentials Store?
Using CredentialManagement (view answer https://stackoverflow.com/a/17747020/206730).
Maybe useful using Powershell too:
CredMan.ps1
https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Credentials-d44c3cde
I cannot list all credentials stored.
There is a Nuget library that I've been using called CredentialManagement http://nuget.org/packages/CredentialManagement/
The usage is pretty simple. I wrapped it a little but probably didn't need to:
Sample usage:
If you're interested in implementing it yourself, browse the source: http://credentialmanagement.codeplex.com/SourceControl/latest
The trick is that there is no C# API into the Credential Manager. This library wraps the other .dll entry points nicely. :-)
This works from a Windows 2k12, I don't have a Win 8 box to test from
http://blogs.msdn.com/b/cdndevs/archive/2013/10/02/using-windows-8-winrt-apis-in-net-desktop-applications.aspx
In short
You can then use this(from here):
The answer from Randy uses
System.String
to store the password, which is unsafe. You will want to useSystem.Security.SecureString
for that purpose.You would be better off if you just read Credential Management with the .NET Framework 2.0.