credwrite (advapi32)
Last changed: -194.146.189.99

.
Summary
TODO - a short description

C# Signature:

[DllImport("Advapi32.dll", SetLastError = true)]
static extern bool CredWrite([In] ref Credential userCredential, [In] UInt32 flags);

VB Signature:

Declare Function CredWrite Lib "advapi32.dll" (TODO) As TODO

User-Defined Types:

[StructLayout(LayoutKind.Sequential)]
private struct Credential
{
     public UInt32 flags;
     public UInt32 type;
     public string targetName;
     public string comment;
     public COMTypes.FILETIME lastWritten;
     public UInt32 credentialBlobSize;
     public IntPtr credentialBlob;
     public UInt32 persist;
     public UInt32 attributeCount;
     public IntPtr credAttribute;
     public string targetAlias;
     public string userName;
}

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

internal static void AddDomainUserCredential(string target, string userName, string password)
{
     Credential userCredential = new Credential();

     userCredential.targetName = target;
     userCredential.type = CredentialTypeDomainPassword;
     userCredential.userName = userName;
     userCredential.attributeCount = 0;
     userCredential.persist = CredentialPersistEnterprise;
     byte[] bpassword = Encoding.Unicode.GetBytes(password);
     userCredential.credentialBlobSize = (UInt32)bpassword.Length;
     userCredential.credentialBlob = Marshal.StringToCoTaskMemUni(password);
     if (!Unmanaged.CredWrite(ref userCredential, 0))
     {
     throw new Win32Exception(Marshal.GetLastWin32Error());
     }
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation