用程序方式创建系统用户

    技术2022-05-11  57

    private bool CreateNTUser(string Username,string Userpassword,string Path)   {    DirectoryEntry obDirEntry = null;    try    {     obDirEntry = new DirectoryEntry("WinNT://" + Environment.MachineName);     DirectoryEntry obUser = obDirEntry.Children.Add(Username, "User"); //增加用户名     obUser.Properties["FullName"].Add(Username); //用户全称     obUser.Invoke("SetPassword", Userpassword); //用户密码     obUser.Invoke("Put", "Description","三恩信息技术网络考试系统访问帐户");//用户详细描述     //obUser.Invoke("Put","PasswordExpired",1); //用户下次登录需更改密码     obUser.Invoke("Put","UserFlags",66049); //密码永不过期     obUser.Invoke("Put","HomeDirectory",Path); //主文件夹路径     obUser.CommitChanges();//保存用户     DirectoryEntry grp = obDirEntry.Children.Find("Administrators", "group");//Users组     if(grp.Name!="")     {      grp.Invoke("Add",obUser.Path.ToString());//将用户添加到某组     }     return true;    }    catch    {     return false;    }   }  

    最新回复(0)