计算机配置\Windows 设置\安全设置\本地策略\用户权限分配可以通过编程实现吗
解决方案 »
- 现在在写extjs tree,但是treeloader会出现问题,不知道什么问题,想请教一下大神。。。
- 秒表的精度问题
- 这段VBA代码用C#怎么获得结果?
- Repeater嵌套UpdatePanel中的button事件
- 强制类性转换
- 最近工作、泡mm都有点看得见、摸不着的感觉,进退两难的境地,散分散散心情.
- 求助,兄弟的毕业设计,哪位仁兄帮帮忙
- 100请谁发一个小程序序难我,从SQL SERVER读出数据,验证用户名和密码是否正确。如果正确就登陆主窗口。登陆窗口关闭。
- 关于事务与SqlDataAdapter
- 【求助】WPF,如何将一组用户控件中,赋值有变化的控件名和变化后的值存入集合,在点击确定时统一校验并保存
- ExecuteReader 要求已打开且可用的连接。连接的当前状态为已关闭。
- 能不能举几个泛型最简单的例子?
如果你用administrator登陆自然没有问题
如果你用guest登陆,使用你的程序是怎样也控制不了的。
你要做的话,首先要符合windows机制的原理。
这个需要服务器的支持的哦,如果没有服务器的话,建议在程序中实现权限分配和管理~....
我是在windows server 2003服务器上,不过不知道是否属于ACTIVE DIRECTORY。
我们在机器上可以操作,编程调用一些API不就可以实现了?哈哈,理论上是这样,只是我们不知道用哪些API罢了~:)_____嘿嘿,发几句废话先~.
需要告诉大家的:所有组织单位下的用户都在Users(容器)--Demain Users(组)中
用代码进行访问时,如果你是域管理员用户,则可以做任何操作,否则,只能查询用户属性。 private void SearchUser()
{
string domainName = "Domain";
string groupName = "Domain Users";
string dirmemName="";
//在Domain Users域用户里取得每个用户名
System.DirectoryServices.DirectoryEntry group = new System.DirectoryServices.DirectoryEntry("WinNT://" + domainName + "/" + groupName + ",group");
foreach(Object member in (IEnumerable)group.Invoke("Members"))
{
//根据很个用户生成如:"LDAP://OU=套装软体课,OU=系统开发部,OU=资讯服务处,OU=营运支援中心,OU=XX公司,DC=Domain,DC=com,DC=cn"
System.DirectoryServices.DirectoryEntry dirmem = new System.DirectoryServices.DirectoryEntry(member);
dirmemName=dirmem.Name;
string DomainName="Domain";
string FilterStr = "(sAMAccountname="+dirmemName+")";
System.DirectoryServices.DirectorySearcher FindMe = new System.DirectoryServices.DirectorySearcher(DomainName);
FindMe.Filter = FilterStr;
System.DirectoryServices.SearchResult FindRes = FindMe.FindOne();
System.DirectoryServices.DirectoryEntry MyUser = FindRes.GetDirectoryEntry();
string OUPath=MyUser.Parent.Path;
//找到该用户所在的LDAP:后,由域管理员登录,并取得该用户的所在属性。
string strFieldsValue="",strFields="";
System.DirectoryServices.DirectoryEntry myds=new System.DirectoryServices.DirectoryEntry(OUPath,"域管理员名","域管理员密码");
foreach(System.DirectoryServices.DirectoryEntry tempEntry in myds.Children)
{
if(tempEntry.SchemaClassName.ToString() == "user" && tempEntry.Properties["sAMAccountName"].Value.ToString().ToLower()==dirmemName)
{
foreach (string propertyName in tempEntry.Properties.PropertyNames )
{
string oneNode = propertyName + ": " +
entry.Properties[propertyName][0].ToString();
this.Textbox1.Text=oneNode;
}
} -------------------------------------------public void AddUser(string strPath,string Username,string ChineseName)//strPath 增加用户至哪个组织单位如"LDAP://OU=XX公司,DC=Domain,DC=com"帐号、中文名{
try
{
string RootDSE;
//System.DirectoryServices.DirectorySearcher DSESearcher= new System.DirectoryServices.DirectorySearcher();
//RootDSE=DSESearcher.SearchRoot.Path;
//RootDSE="LDAP://DC=Domain,DC=com";
//RootDSE=RootDSE.Insert(7,"CN=Users,");
System.DirectoryServices.DirectoryEntry myDE = new System.DirectoryServices.DirectoryEntry(strPath);
System.DirectoryServices.
DirectoryEntries myEntries = myDE.Children;
// Create a new entry 'Sample' in the container.
string strname="CN="+ChineseName;
System.DirectoryServices.DirectoryEntry myDirectoryEntry = myEntries.Add(strname, "user"); //MessageBox.Show(myDirectoryEntry.SchemaClassName.ToString());
myDirectoryEntry.Properties["userPrincipalName"].Value=Username;
myDirectoryEntry.Properties["name"].Value=ChineseName;
myDirectoryEntry.Properties["samAccountName"].Value=Username;
myDirectoryEntry.Properties["userAccountControl"].Value =66048; //590336;
myDirectoryEntry.CommitChanges();
}
----------------------------------------------private void addOU(string strPath,string OUName)//增加组织到strPath组织单位下,组织名称
{
try
{
//String RootDSE;
//System.DirectoryServices.DirectorySearcher DSESearcher= new System.DirectoryServices.DirectorySearcher();
//RootDSE=DSESearcher.SearchRoot.Path;
//RootDSE="LDAP://OU=百意时尚广场,DC=Domain,DC=com"; System.DirectoryServices.DirectoryEntry myDE = new System.DirectoryServices.DirectoryEntry(strPath);
System.DirectoryServices.DirectoryEntries myEntries = myDE.Children;
string name="OU="+OUName;
System.DirectoryServices.DirectoryEntry myDirectoryEntry = myEntrie
s.Add(name,"organizationalUnit"); myDirectoryEntry.Properties["name"].Value=OUName;
myDirectoryEntry.Properties["instanceType"].Value=4;
myDirectoryEntry.Properties["distinguishedName"].Value="OU="+OUName+",DC=Domain,DC=COM)";
myDirectoryEntry.Properties["objectCategory"].Value="CN=Organizational-Unit,CN=Schema,CN=Configuration,DC=sedep,DC=COM";
myDirectoryEntry.Properties["ou"].Value=OUName;
myDirectoryEntry.Properties["postalCode"].Value="777"; myDirectoryEntry.CommitChanges();
//UserMoveto("LDAP://OU="+OUName+",DC=sedep,DC=com",strPath);
}
catch(Exception RaiseErr)
{
MessageBox.Show (RaiseErr.Message);
}
} ---------------------------------------------private void ModifyUser()
{
try
{
string DomainName="Domain";
string FilterStr = "(sAMAccountname=karlluo)";
System.DirectoryServices.DirectorySearcher FindMe = new System.DirectoryServices.DirectorySearcher(DomainName);
FindMe.Filter = FilterStr;
System.DirectoryServices.SearchResult FindRes = FindMe.FindOne();
string tt=FindRes.Path;
System.DirectoryServices.DirectoryEntry MyUser = FindRes.GetDirectoryEntry();
string OUPath=MyUser.Parent.Path; DirectoryEntry myds=new DirectoryEntry(OUPath,"域管理员名","域管理员密码"); foreach(System.DirectoryServices.DirectoryEntry tempEntry in myds.Children)
{
if(tempEntry.SchemaClassName.ToString() == "user")
{
if(tempEntry.Properties["sAMAccountName"].Value.ToString().ToLower()=="karlluo")
{
tempEntry.UsePropertyCache=true;
tempEntry.Properties["st"].Value="yyyyyyyyyyyyyyyy";
//newEntry.Properties["userPrincipalName"].Value="userID";
tempEntry.CommitChanges();
}
}
}
}
catch(Exception RaiseErr)
{
MessageBox.Show (RaiseErr.Message);
} }
一个用active directory实现组策略的代码
不知道具体是那些属性