惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
F
Fortinet All Blogs
J
Java Code Geeks
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
P
Privacy International News Feed
V
Visual Studio Blog
Martin Fowler
Martin Fowler
博客园 - 司徒正美
A
Arctic Wolf
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
Scott Helme
Scott Helme
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Proofpoint News Feed
P
Palo Alto Networks Blog
S
Securelist
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threatpost
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
K
Kaspersky official blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Exploit Database - CXSecurity.com
Google DeepMind News
Google DeepMind News
A
About on SuperTechFans
月光博客
月光博客
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CXSECURITY Database RSS Feed - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
Y
Y Combinator Blog
PCI Perspectives
PCI Perspectives
S
Security Affairs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
O
OpenAI News
Google Online Security Blog
Google Online Security Blog
The Hacker News
The Hacker News
博客园 - Franky
Attack and Defense Labs
Attack and Defense Labs
Hugging Face - Blog
Hugging Face - Blog
N
Netflix TechBlog - Medium
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog

博客园 - 北极熊,我来了!

C#获取类以及类下的方法(用于Asp.Net MVC) 使用JavaScript判断用户是否为手机设备 手机端页面自适应解决方案 Asp 邮件发送代码 js 日期字符串转换成日期类型,判断星期几 浅析a标签的4个伪类 C#读取Rss功能函数 《中文防止乱码的万能解决方案》 《小偷程序:自动获取百度天气预报》 Asp.NET使用HTML控件上传文件 《JS两级联动菜单学习全接触》 活动目录ADSI实现添加系统帐号问题!!! 中国频道空间使用Jmail发送邮件 《IP地址和数字之间转化的算法》 《单域名下整合动网、动易、OBlog程序》 JS读取XML数据 Asp.NET读取Excel数据 [XML系列]Flash读取XML数据 《省市联动功能菜单的实现》
ADSI管理Windows2003系统帐号
北极熊,我来了! · 2007-05-20 · via 博客园 - 北极熊,我来了!

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

using System;
using System.DirectoryServices;
using System.Collections;

namespace CNVP.FM.IISControlService
{
    
/// <summary>
    
/// 实现在开通IIS站点时候自动对系统帐号进行添加删除操作
    
/// </summary>

    public class UserManager
    
{
        
public UserManager()
        
{
            
        }

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

                
//NewUser.Properties["UserFlags"].Add(0x0002);//禁用登录帐号
                
//NewUser.Properties["UserFlags"].Add(0x0040);//用户不能更改密码
                ArrayList arl = new ArrayList();
                arl.Add(
0x0002);
                arl.Add(
0x0040);
                arl.Add(
0x10000);
                NewUser.Properties[
"UserFlags"].Value = arl.ToArray();

                
//NewUser.Properties["UserFlags"].Add(0x10000);//用户密码永不到期

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

                ObjUser.Close();
                AD.Close();
                
return true;
            }

            
catch
            
{
                
return false;
            }

        }

        
/// <summary>
        
/// 修改IIS登录帐号密码
        
/// </summary>
        
/// <param name="Accounts">登录帐号</param>
        
/// <param name="Password">登录密码</param>
        
/// <returns></returns>

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

            
catch
            
{
                
return false;
            }

        }

        
/// <summary>
        
/// 删除IIS登录帐号
        
/// </summary>
        
/// <param name="Accounts">登录帐号</param>
        
/// <returns></returns>

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

            
catch
            
{
                
return false;
            }

        }

    }

}