参考文章: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=110
界面上放两个文本框和一个按钮
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.DirectoryServices;
//
必须现在解决方案资源管理器引用该dll

/**/
/*
///Coder:LinQifo
///Date:2008-5-10
///Platform:VS 2005+WinXP Ghost SP2
/// For CJZ
/// She don't know how to change pwd ,so I wrote this little code!
*/
namespace
ChangeAdminPwd
...
{
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
...{
if (textBox1.Text != textBox2.Text)
...{
MessageBox.Show("两次输入的密码不一样!");
return;
}
String str = "WinNT://";
str += System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace('/','/');
str += ",User";
// MessageBox.Show(str);
try
...{
DirectoryEntry myDirectoryEntry;
myDirectoryEntry = new DirectoryEntry(str);
myDirectoryEntry.Invoke("setPassword", textBox1.Text);
myDirectoryEntry.CommitChanges();
if (textBox1.Text != "")
...{
MessageBox.Show("当前用户的密码已经设置为:" + textBox1.Text + ' ' + " 请牢记!");
}
else
...{
MessageBox.Show("您设置了空密码!");
}
}
catch (Exception exp)
...{
MessageBox.Show(exp.ToString());
}
finally
...{
}
}
}
}
3万+

被折叠的 条评论
为什么被折叠?



