是一个删除系统账号,删除系统组的问题PrincipalContext MyComputer=new PrincipalContext(ContextType.Machine);
UserPrincipal usr=new UserPrincipal(MyComputer);
usr.SamAccountName="admin";
usr.SetPassword("admin");
usr.Save();
usr.Dispose();
这是简单的完成一个账号的添加
但是删除,不知如何编号?一直没找到方法
不能使用
usr.Delete();但方法确实是这样的,只是
UserPrincipal usr=new UserPrincipal(MyComputer);
这个地方不能这么写,有研究过这个的吗?
UserPrincipal usr=new UserPrincipal(MyComputer);
usr.SamAccountName="admin";
usr.SetPassword("admin");
usr.Save();
usr.Dispose();
这是简单的完成一个账号的添加
但是删除,不知如何编号?一直没找到方法
不能使用
usr.Delete();但方法确实是这样的,只是
UserPrincipal usr=new UserPrincipal(MyComputer);
这个地方不能这么写,有研究过这个的吗?
我的是VS2005,你们用的是哪个版本啊?
以下是程序中其中一段代码:
//删除账号
private void User_del()
{
PrincipalContext MyComputer = new PrincipalContext(ContextType.Machine);
try
{
SqlConnection conn = new SqlConnection(Hit.Config.DBConn.SqlConn);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = @"select * from [Config]";
cmd.CommandType = CommandType.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
bool b = reader.Read();
if (b)
{
Hit.Config.Config.usr = "正在删除账号...";
UI_install_log();
UserPrincipal usr = UserPrincipal.FindByIdentity(MyComputer,reader["User_name"].ToString());
if (usr == null)
{
Hit.Config.Config.usr = "账号不存在,有可能同步未完成导致,请手动删除";
UI_install_log();
}
else
{
usr.Delete();
usr.Dispose();
Hit.Config.Config.usr = "账号删除成功!";
UI_install_log();
}
}
}
catch
{
MessageBox.Show("读取数据库出错::错误代码506", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}