static void Main()
{
SecureString password = new SecureString();
string pass = "123456";
foreach (char c in pass)
{
password.AppendChar(c);
}
IntPtr pPassword = Marshal.SecureStringToGlobalAllocUnicode(password);
USER_INFO_1003 ui = new USER_INFO_1003();
ui.usri1003_password=Marshal.SecureStringToGlobalAllocUnicode(password);
int err=NetUserSetInfo(".", "home", 1003, ref ui, 0);
Marshal.ZeroFreeGlobalAllocUnicode(pPassword);
Console.Read();
}
[DllImport("Netapi32.dll")]
extern public static int NetUserSetInfo(
[MarshalAs(UnmanagedType.LPWStr)] string servername,
[MarshalAs(UnmanagedType.LPWStr)] string username,
int level,
ref USER_INFO_1003 buf,
int error);
public struct USER_INFO_1003
{
public IntPtr usri1003_password;
}