- using System;
- using System.DirectoryServices;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- private static object obComputer;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void AddUser(string Username, string Userpassword)
- {
- string path = String.Format("WinNT://{0}", System.Environment.MachineName);
- DirectoryEntry entryPC = new DirectoryEntry(path);
- DirectoryEntry obUser = entryPC.Children.Add(Username, "User");
- obUser.Properties["Description"].Add(Username);
- obUser.Properties["FullName"].Add(Username);
- object obRet = obUser.Invoke("SetPassword", Userpassword);
- obUser.CommitChanges();
- MessageBox.Show("用户添加成功,用户名为:" + Username + "密码为:" + Userpassword);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (textBox1.Text == "" || textBox2.Text == "")
- {
- MessageBox.Show("用户名或密码不能为空,请重新填写");
- }
- else
- {
- string Username = textBox1.Text;
- string Userpassword = textBox2.Text;
- AddUser(Username, Userpassword);
- MessageBox.Show("添加成功啦,返回啦");
- }
- }
- }
- }
亲爱的:被墙域名跳转TG:@qianhenetwork QQ:851617266,可否收藏+评论+分享呢?
文章评论 本文章有个评论