Abstractions.WindowsApi.pInvokes.UserADD C# (CSharp) Метод

UserADD() публичный статический Метод

add user to the local system based on http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/B70B79D9-971F-4D6F-8462-97FC126DE0AD
public static UserADD ( string username, string password, string comment ) : Boolean
username string
password string
comment string
Результат Boolean
        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;
        }