C#修改xp 密码

 参考文章: 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
            

                
            }

        }


    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值