[DllImport("Advapi32.dll", SetLastError = true)]
static extern bool CredWrite([In] ref Credential userCredential, [In] UInt32 flags);
Declare Function CredWrite Lib "advapi32.dll" (TODO) As TODO
[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;
}
None.
Please add some!
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());
}
}
Do you know one? Please contribute it!