b/s结构下客户端(IE)向服务器(IIS)上创建系统用户 我做了一个b/s网页,需要实现在客户端增加一个系统用户同时要在服务上也增加一个Windows用户,有没有办法实现呢?我用Process执行dos命令net user在Debug下是可以的,发布到IIS上就报访问错误。请问有没有办法实现呀?在线等……没分了就这些了,谢谢大拿们了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 net_lover 于 2010-09-02 09:09:11 编辑 //WinNT用户管理 using System; using System.DirectoryServices; namespace Host.AdminManager.Inc { public class WindwosUser { //创建NT用户 //传入参数:Username要创建的用户名,Userpassword用户密码,Path主文件夹路径 public static bool CreateNTUser(string Username,string Userpassword,string Path) { DirectoryEntry obDirEntry = null; try { obDirEntry = new DirectoryEntry("WinNT://" + Environment.MachineName); DirectoryEntry obUser = obDirEntry.Children.Add(Username, "User"); //增加用户名 obUser.Properties["FullName"].Add(Username); //用户全称 obUser.Invoke("SetPassword", Userpassword); //用户密码 obUser.Invoke("Put", "Description","Test User from .NET");//用户详细描述 //obUser.Invoke("Put","PasswordExpired",1); //用户下次登录需更改密码 obUser.Invoke("Put","UserFlags",66049); //密码永不过期 obUser.Invoke("Put","HomeDirectory",Path); //主文件夹路径 obUser.CommitChanges();//保存用户 DirectoryEntry grp = obDirEntry.Children.Find("Users", "group");//Users组 if(grp.Name!="") { grp.Invoke("Add",obUser.Path.ToString());//将用户添加到某组 } return true; } catch { return false; } } //删除NT用户 //传入参数:Username用户名 public static bool DelNTUser(string Username) { try { DirectoryEntry obComputer = new DirectoryEntry("WinNt://" + Environment.MachineName);//获得计算机实例 DirectoryEntry obUser = obComputer.Children.Find(Username,"User");//找得用户 obComputer.Children.Remove(obUser);//删除用户 return true; } catch { return false; } } //修改NT用户密码 //传入参数:Username用户名,Userpassword用户新密码 public static bool InitNTPwd(string Username,string Userpassword) { try { DirectoryEntry obComputer = new DirectoryEntry("WinNt://" + Environment.MachineName); DirectoryEntry obUser = obComputer.Children.Find(Username,"User"); obUser.Invoke("SetPassword", Userpassword); obUser.CommitChanges(); obUser.Close(); obComputer.Close(); return true; } catch { return false; } } } } B/S结构控制客户端PC创建用户,需要很高权限吧,感觉有点儿像病毒了 本帖最后由 net_lover 于 2010-09-02 09:20:28 编辑 你把项目文件夹的权限设为everyone asp.net保存时组装xml保存到数据库 如何根据 System.Environment.OSVersion 来分析用户使用的操作系统 如果读取最简单的天气信息? 如何用正则替换内容的关键字 自定义MyMembership,运行时报错web.config中无法找到程序集 IE或Firefox的错误控制台 紧急问题,log4net,会生成多个文件名。 请问了 怎样验证用户名是否存在时弹出对话框? 当选中datagrid的某行时,怎样让这一行获得焦点(改变颜色)? JS获取COOKIE 用asp.net实现智能建站系统的原理
using System;
using System.DirectoryServices;
namespace Host.AdminManager.Inc
{
public class WindwosUser
{
//创建NT用户
//传入参数:Username要创建的用户名,Userpassword用户密码,Path主文件夹路径
public static bool CreateNTUser(string Username,string Userpassword,string Path)
{
DirectoryEntry obDirEntry = null;
try
{
obDirEntry = new DirectoryEntry("WinNT://" + Environment.MachineName);
DirectoryEntry obUser = obDirEntry.Children.Add(Username, "User"); //增加用户名
obUser.Properties["FullName"].Add(Username); //用户全称
obUser.Invoke("SetPassword", Userpassword); //用户密码
obUser.Invoke("Put", "Description","Test User from .NET");//用户详细描述
//obUser.Invoke("Put","PasswordExpired",1); //用户下次登录需更改密码
obUser.Invoke("Put","UserFlags",66049); //密码永不过期
obUser.Invoke("Put","HomeDirectory",Path); //主文件夹路径
obUser.CommitChanges();//保存用户
DirectoryEntry grp = obDirEntry.Children.Find("Users", "group");//Users组
if(grp.Name!="")
{
grp.Invoke("Add",obUser.Path.ToString());//将用户添加到某组
}
return true;
}
catch
{
return false;
}
}
//删除NT用户
//传入参数:Username用户名
public static bool DelNTUser(string Username)
{
try
{
DirectoryEntry obComputer = new DirectoryEntry("WinNt://" + Environment.MachineName);//获得计算机实例
DirectoryEntry obUser = obComputer.Children.Find(Username,"User");//找得用户
obComputer.Children.Remove(obUser);//删除用户
return true;
}
catch
{
return false;
}
}
//修改NT用户密码
//传入参数:Username用户名,Userpassword用户新密码
public static bool InitNTPwd(string Username,string Userpassword)
{
try
{
DirectoryEntry obComputer = new DirectoryEntry("WinNt://" + Environment.MachineName);
DirectoryEntry obUser = obComputer.Children.Find(Username,"User");
obUser.Invoke("SetPassword", Userpassword);
obUser.CommitChanges();
obUser.Close();
obComputer.Close();
return true;
}
catch
{
return false;
}
}
}
}