• NetUserGetInfo NetUserAdd


    [DllImport("Netapi32.dll")]
            extern static int NetUserGetInfo([MarshalAs(UnmanagedType.LPWStr)] string servername, [MarshalAs(UnmanagedType.LPWStr)] string username, int level, out IntPtr bufptr);


            [DllImport("Netapi32.dll")]
            extern static int NetUserAdd([MarshalAs(UnmanagedType.LPWStr)] string servername, int level, ref USER_INFO_1 buf, int parm_err);
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            public struct USER_INFO_1
            {
                public string usri1_name;
                public string usri1_password;
                public int usri1_password_age;
                public int usri1_priv;
                public string usri1_home_dir;
                public string comment;
                public int usri1_flags;
                public string usri1_script_path;
            }

            private void button1_Click(object sender, EventArgs e)
            {
                IntPtr bufPtr;
                USER_INFO_1 User = new USER_INFO_1();
                if (NetUserGetInfo(null, "Administrato", 1, out bufPtr) != 0)
                {
                    // MessageBox.Show("Error Getting User Info","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                User = (USER_INFO_1)Marshal.PtrToStructure(bufPtr, typeof(USER_INFO_1));

            }

            private void button2_Click(object sender, EventArgs e)
            {
                USER_INFO_1 NewUser = new USER_INFO_1(); // Create an new instance of the USER_INFO_1 struct

                NewUser.usri1_name = "UserTestOne"; // Allocates the username
                NewUser.usri1_password = "password"; // allocates the password
                NewUser.usri1_priv = 1; // Sets the account type to USER_PRIV_USER
                NewUser.usri1_home_dir = null; // We didn’t supply a Home Directory
                NewUser.comment = ""; // Comment on the User
                NewUser.usri1_script_path = null; // We didn’t supply a Logon Script Path

                if (NetUserAdd(null, 1, ref NewUser, 0) != 0) // If the call fails we get a non-zero value
                {
                    //MessageBox.Show("Error Adding User", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }

  • 相关阅读:
    AWS的EC2实例搭建服务器使用stackoverflow教程
    亚马逊云开服之旅
    Linux主机之间ssh免密登录配置方法
    阿里云运维培训讲解
    区块链技术在物流领域应用分析
    公众号页面分享朋友圈后点击跳转到小程序的方法介绍
    数据库主库从库宕机重启后binlog数据同步
    Docker+ElasticSearch+Logstash+Kibana+Filebeat搭建方法
    linux实现磁盘自动挂载脚本
    阿里云ecs基于镜像进行旧服务器迁移到新服务器
  • 原文地址:https://www.cnblogs.com/ahuo/p/1659138.html
Copyright © 2020-2023  润新知