예제 #1
0
        /// <summary>
        /// 指定した認証情報を書き込みます。
        /// </summary>
        /// <param name="Credential">認証情報</param>
        /// <param name="Flags"></param>
        public static void Write(WinCred.Credential Credential, CredWriteFlags Flags)
        {
            var uc = new Credential();

            using (uc.Copy(Credential))
                uc.Write(Flags);
        }
예제 #2
0
        /// <summary>
        /// 資格情報の登録
        /// </summary>
        /// <param name="unmanagedCred"></param>
        /// <param name="Flags"></param>
        public void Write(CredWriteFlags Flags = default(CredWriteFlags))
        {
            if (Interop.CredWrite(ref this, Flags))
            {
                return;
            }
            var hresult   = Marshal.GetHRForLastWin32Error();
            var exception = Marshal.GetExceptionForHR(hresult);

            if (unchecked ((uint)hresult) == 0x80070032)
            {
                throw new NotSupportedException("not support.", exception);
            }
            throw exception;
        }
예제 #3
0
        /// <summary>
        /// Writes a credential to the Credential Manager Password Vault
        /// </summary>
        /// <param name="credential">The credential to store</param>
        /// <param name="flags">Write flags</param>
        public static void Write(Credential credential, CredWriteFlags flags = 0x0)
        {
            CREDENTIAL NewCred = credential.ToWin32Credential();

            try
            {
                bool Success = CredWrite(ref NewCred, (UInt32)flags);

                if (!Success)
                {
                    int Err = Marshal.GetLastWin32Error();
                    ThrowLastWin32Error();
                }
            }
            finally
            {
                Marshal.FreeHGlobal(NewCred.TargetName);
                Marshal.FreeHGlobal(NewCred.CredentialBlob);
                Marshal.FreeHGlobal(NewCred.UserName);
                Marshal.FreeHGlobal(NewCred.Comment);
                Marshal.FreeHGlobal(NewCred.TargetAlias);
                Marshal.FreeHGlobal(NewCred.Attributes);
            }
        }
예제 #4
0
 public static extern bool CredWrite(ref Unmanaged.Credential credential, CredWriteFlags flags);