Skip to content

Commit

Permalink
Return empty result when there are no credentials on the system.
Browse files Browse the repository at this point in the history
  • Loading branch information
skyguy94 committed Jun 2, 2015
1 parent ffcc6c2 commit 351ee75
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion poshring/CredentialsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ public IEnumerable<Credential> GetCredentials()
IntPtr ptr;
if (!UnsafeAdvapi32.CredEnumerateW(null, 0x1, out count, out ptr))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
var error = (CredentialErrors) Marshal.GetLastWin32Error();
switch (error)
{
case CredentialErrors.NotFound:
return Enumerable.Empty<Credential>();
case CredentialErrors.NoSuchLogonSession:
case CredentialErrors.InvalidFlags:
throw new Win32Exception((int)error);
default:
throw new InvalidOperationException("Unexpected error while fetching credentials.");
}
}

var credentials = Enumerable.Range(0, count)
Expand Down

0 comments on commit 351ee75

Please sign in to comment.