public static Boolean UserADD(string username, string password, string comment)
{
SafeNativeMethods.USER_INFO_1 NewUser = new SafeNativeMethods.USER_INFO_1();
NewUser.usri1_name = username; // Allocates the username
NewUser.usri1_password = password; // allocates the password
NewUser.usri1_priv = structenums.UserPrivileges.USER_PRIV_USER; // Sets the account type to USER_PRIV_USER
NewUser.usri1_home_dir = null; // We didn't supply a Home Directory
NewUser.comment = comment;// "pGina created pgSMB"; // Comment on the User
NewUser.usri1_script_path = null; // We didn't supply a Logon Script Path
Int32 ret;
SafeNativeMethods.NetUserAdd(Environment.MachineName, 1, ref NewUser, out ret);
//2224 The user account already exists. NERR_UserExists
if ((ret != 0) && (ret != 2224)) // If the call fails we get a non-zero value
{
LibraryLogging.Error("NetUserAdd error:{0} {1}", ret, LastError());
return false;
}
return true;
}