CredDelete() private method

private CredDelete ( string TargetName, CredTypes Type, int Flags ) : bool
TargetName string
Type CredTypes
Flags int
return bool
        private bool DeleteCredential(string key)
        {
            Argument.IsNotNullOrWhitespace(() => key);

            var found = false;

            Log.Debug("Deleting credentials with key '{0}'", key);

            if (CredUi.CredDelete(key, CredUi.CredTypes.CRED_TYPE_GENERIC, 0))
            {
                Log.Debug("Successfully deleted credentials");

                found = true;
            }
            else
            {
                var error = Marshal.GetLastWin32Error();
                if (error != (int)CredUi.CredUiReturnCodes.ERROR_NOT_FOUND)
                {
                    throw Log.ErrorAndCreateException(x => new CredentialException(error),
                                                      "Failed to delete credentials, error code '{0}'", error);
                }
            }

            return(found);
        }
Beispiel #2
0
        private static bool DeleteCredential(string key)
        {
            Argument.IsNotNullOrWhitespace(() => key);

            var found = false;

            if (CredUi.CredDelete(key, CredUi.CredTypes.CRED_TYPE_GENERIC, 0))
            {
                found = true;
            }
            else
            {
                var error = Marshal.GetLastWin32Error();
                if (error != (int)CredUi.CredUiReturnCodes.ERROR_NOT_FOUND)
                {
                    throw new CredentialException(error);
                }
            }

            return(found);
        }