Можно пример с ним? У меня на XP ругается, что "Неверный дескриптор", а на 2008 просто падает. Код прилагаю(на C#): Код (Text): using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Runtime.InteropServices; using ComTypes = System.Runtime.InteropServices.ComTypes; using Microsoft.Win32; namespace WindowsFormsApplication1 { [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal struct USER_INFO_1 { [MarshalAs(UnmanagedType.LPWStr)] public string sUsername; [MarshalAs(UnmanagedType.LPWStr)] public string sPassword; public uint uiPasswordAge; public uint uiPriv; [MarshalAs(UnmanagedType.LPWStr)] public string sHome_Dir; [MarshalAs(UnmanagedType.LPWStr)] public string sComment; public uint uiFlags; [MarshalAs(UnmanagedType.LPWStr)] public string sScript_Path; } public class UACreator { [DllImport("netapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern int NetUserAdd( [MarshalAs(UnmanagedType.LPWStr)] string servername, UInt32 level, IntPtr userInfo, out UInt32 parm_err); public static string UserAdd(string name, string password) { USER_INFO_1 user = new USER_INFO_1(); user.sUsername = name.Trim(); user.sPassword = password; user.uiPriv = 1; user.sScript_Path = ""; user.sHome_Dir = ""; user.sComment = "Autogenerated user account"; IntPtr userPtr = Marshal.AllocHGlobal(Marshal.SizeOf(user)); Marshal.StructureToPtr(user, userPtr, true); uint outVal = 0; int result = NetUserAdd("", 1, userPtr, out outVal); if (result != 0) { return new System.ComponentModel.Win32Exception(result).Message; } else { return "Success"; } } } } //MessageBox.Show(UserAdd("bebe", "bebe"));
Код (Text): C:\!Docs\!!projects\NetUserAdd\Release>NetUserAdd.exe bebe bebe A system error has occurred: 53 WTF?