ADSI管理Windows2003系统帐号

     最近在开发一个虚拟主机管理的软件,需要用到用户权限管理这块,上网找了找资料,发现ADSI这块还不错,好像还有另外的一个新的东西可以实现操作用户帐号的功能,那个以后在研究下吧,操作Window2003用户的代码如下:

None.gif using  System;
None.gif
using  System.DirectoryServices;
None.gif
using  System.Collections;
None.gif
None.gif
namespace  CNVP.FM.IISControlService
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 实现在开通IIS站点时候自动对系统帐号进行添加删除操作
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class UserManager
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public UserManager()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建IIS登录帐号
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="Accounts">登录帐号</param>
InBlock.gif        
/// <returns></returns>
      
InBlock.gif        
public static bool CreateUser(string Accounts)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DirectoryEntry AD 
= new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
InBlock.gif                DirectoryEntry NewUser 
= AD.Children.Add(Accounts, "user");//增加用户名
ExpandedSubBlockStart.gifContractedSubBlock.gif
                NewUser.Invoke("SetPassword"new object[] dot.gif"LanTian123456" });//用户密码
ExpandedSubBlockStart.gifContractedSubBlock.gif
                NewUser.Invoke("Put"new object[] dot.gif"FullName", Accounts });//用户全称  
ExpandedSubBlockStart.gifContractedSubBlock.gif
                NewUser.Invoke("Put"new object[] dot.gif"Description""太平洋主机管理帐号" });//用户详细描述
InBlock.gif
                NewUser.Invoke("Put""PasswordExpired"0);//用户下次登录需更改密码
InBlock.gif                
//NewUser.Invoke("Put", "UserFlags", 66049);//密码永不过期
InBlock.gif                
//NewUser.Invoke("Put", "HomeDirectory", Path); //主文件夹路径
InBlock.gif
InBlock.gif                
//NewUser.Properties["UserFlags"].Add(0x0002);//禁用登录帐号
InBlock.gif                
//NewUser.Properties["UserFlags"].Add(0x0040);//用户不能更改密码
InBlock.gif
                ArrayList arl = new ArrayList();
InBlock.gif                arl.Add(
0x0002);
InBlock.gif                arl.Add(
0x0040);
InBlock.gif                arl.Add(
0x10000);
InBlock.gif                NewUser.Properties[
"UserFlags"].Value = arl.ToArray();
InBlock.gif
InBlock.gif                
//NewUser.Properties["UserFlags"].Add(0x10000);//用户密码永不到期
InBlock.gif

InBlock.gif                NewUser.CommitChanges();
InBlock.gif                DirectoryEntry ObjUser
=AD.Children.Find("Guests""group");
InBlock.gif                
if (ObjUser.Name != null
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                    ObjUser.Invoke(
"Add"new object[] dot.gif{ NewUser.Path.ToString() }); 
ExpandedSubBlockEnd.gif                }

InBlock.gif                ObjUser.Close();
InBlock.gif                AD.Close();
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 修改IIS登录帐号密码
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="Accounts">登录帐号</param>
InBlock.gif        
/// <param name="Password">登录密码</param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public static bool EditUser(string Accounts, string Password)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DirectoryEntry AD 
= new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
InBlock.gif                DirectoryEntry ObjUser 
= AD.Children.Find(Accounts, "user");
InBlock.gif                ObjUser.Invoke(
"SetPassword", Password);
InBlock.gif                ObjUser.CommitChanges();
InBlock.gif                ObjUser.Close();
InBlock.gif                AD.Close();
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 删除IIS登录帐号
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="Accounts">登录帐号</param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public static bool DelUser(string Accounts)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DirectoryEntry AD 
= new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
InBlock.gif                DirectoryEntry ObjUser 
= AD.Children.Find(Accounts, "user");//找得用户
InBlock.gif                
//AD.Children.Remove(ObjUser);//删除用户
InBlock.gif
                ObjUser.GetType();
InBlock.gif                ObjUser.Close();
InBlock.gif                AD.Close();
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/Apollo/archive/2007/05/20/753088.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值