c# - PInvoke of NetUserAdd returns 24 -
I am calling NetUserAdd and it is returning 24 for each call. Does anyone know 24 stands for? When I do not know what the error is, it is very difficult to debug it.
I'm calling it a Windows XP machine running as a local administrator. I am also a local administrator on the target computer. I tried to do it with USER_INFO_1 and it worked fine. I need a level of control given by USER_INFO_2.
This shows the return value for this call. They are further defined by numeric values. Unfortunately none of these values = 24
I know this is a very specific question. I think I'm hoping to find a PInvoke / NetAddUser expert who can help me out there
Here in case my code matters.
[StructLayout (LayoutKind., Choracet = charset.unycode)] Public structure USER_INFO_2 {name of the public string; Public string password; Public int password_age; Public entities Private; Public string home_dir; Public string comment; Public integer flags; Public string script_path; Public int auth_flags; Public string full_name; Public string usr_comment; Public string params; Public string workstation; Public int last_logon; Public int last_logoff; Public keel acct_expires; Public maximum max_storage; Public int units_per_week; Public IntPtr logon_hours; // This is a PBYTE public int bad_pw_count; Public inter-num_logons; Public string logon_server; Public integration country; Public int code_page; } [DllImport ( "NetApi32.DLL", charset = CharSet.Unicode, SetLastError = true)] private static extern int NetUserAdd ([MarshalAs (UnmanagedType.LPWStr)] string Servername, UInt32 level, referee USER_INFO_2 UserInfo, UInt32 parm_err) out; Private Static Uitine CreateUser (String Computer, String Username, String PSTWdrd, String FULN) {Constt UF_DONT_EXPIRE_PASSWD = 0x10000; Const int UF_ACCOUNTDISABLE = 0x000002; Const int USER_PRIV_GUEST = 0; // lmaccess.h: 656 Constt USER_PRIV_USER = 1; // lmaccess.h: 657 Constt USER_PRIV_ADMIN = 2; // lmaccess.h: 658 USER_INFO_2 userInfo2 = new USER_INFO_2 () {acct_expires = long.MaxValue, auth_flags = 0, // should be 0 NetUserAddCalls bad_pw_count for = -1, // call // ignored for NetUserAdd code_page = Commented? = "Scantrack account", // country_code = ?, Flags = UF_DONT_EXPIRE_PASSWD, // & amp; UF_ACCOUNTDISABLE, full_name = fullname, home_dir = "", last_logoff = 0, Antim_ logon = 0, logon_hours = IntPtr.Zero, // user has no logon time. Logon_server = ""; // Call max_storage = 0, name = username, ignored for num_logons NetUserAdd = -1, // calls ignored for NetUserAdd parms = "", Password = psswrd, password_age = -1 , Priv = USER_PRIV_GUEST, script_path = "", Units_per_week = -1, // ignore netUserAdd call usr_comment = "", workstation = ""}; UIIT output; NetUZAd (computer, 2, referee userinfa 2, out output); Return output; } Private Zero Button 1_Click (Object Sender, EventArgs e) {string computer = "ComputerName"; String user name = "testName"; String psswrd = "! T3st4Stuff"; String fulen = "test name full"; UiIT Output = Contributor (Computer, Username, PSCWDR, FullName); MessageBox.Show (output.ToString ()); }
error .h from:
# Define ... Not sure how it relates to your code, but it is.
Edit : I wonder if this is:
home_dir = "" or Similar - The documentation is called "The Indicator must specify the path of the home directory for the Unicode string usri2_name . For the user specified by the string, the string may be blank." - There is no mention of the string, but is empty, as you have to try null - maybe zero length of the string C means can be ERROR_BAD_LENGTH ..
Comments
Post a Comment