本文介绍了吸引系统用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码获取系统本地用户的列表:

I am trying to get the list of local users of a system using the following code :

内部无效 GetUsers()

internalvoid GetUsers()

{

          ; 尝试

           try

          ;  {

          ;                        列表< 字符串> adUsers = 列表< 字符串> ();

                       List <string > adUsers =new List <string >();

          ;           DirectoryEntry directoryEntry = DirectoryEntry (" WinNT://" ; +环境 .MachineName);

                       DirectoryEntry directoryEntry =new DirectoryEntry ("WinNT://" +Environment .MachineName);

          ;           foreach ( DirectoryEntry 子级 directoryEntry.Children中)

                       foreach (DirectoryEntry childin directoryEntry.Children)

          ;           {

                       {

          ;                           如果(child.SchemaClassName.Equals(用户" StringComparison .OrdinalIgnoreCase))

                                  if (child.SchemaClassName.Equals("User" ,StringComparison .OrdinalIgnoreCase))

;                           {

                                  {

          ;            ;                                       adUsers.Add(child.Name);

                                                          adUsers.Add(child.Name);

          ;                          }

                                  }

          ;           }

                       }

          ;   }

          ; 捕获(异常例如)

           catch (Exception ex)

          ;  {

          ;    //异常

               //Exception

          ;  }

此代码可以正常工作.但是在某些计算机中,它在用户列表中包括诸如ASPNET和HelpAssistant之类的用户.有什么方法可以让我只让实际登录到控制台的用户获得? 即,任何普通用户.我不想列出ASPNET和HelpAssistant

This code works fine. But in some computers, it includes users like ASPNET and HelpAssistant in the list of users. Is there a way in which I can get only the users who actually log in to the console? ie, Any normal user. I do not want to list ASPNET and HelpAssistant

感谢

Ram

Ram

 

推荐答案

DirectorySearcher dSearch = new DirectorySearcher();
dSearch.Filter =(&(objectClass = computer)(objectCategory = computer)(cn = laur *)(!cn = * dc *))";
dSearch.PropertiesToLoad.Add("cn");
ArrayList allComputers = new ArrayList();
foreach(dSearch.FindAll()中的SearchResult结果)
{
   字符串fqn = GetProperty(结果,"cn")+". + ldapPath;
    allComputers.Add(fqn);
}

DirectorySearcher dSearch = new DirectorySearcher();
dSearch.Filter = "(&(objectClass=computer)(objectCategory=computer)(cn=laur*)(!cn=*dc*))";
dSearch.PropertiesToLoad.Add("cn");
ArrayList allComputers = new ArrayList();
foreach (SearchResult result in dSearch.FindAll())
{
    string fqn = GetProperty(result, "cn") + "." + ldapPath;
    allComputers.Add(fqn);
}

对于您的用户,您可以使用&(objectCategory = person)(objectClass = user)".您还可以根据系统工程师如何设置域来检查AD对象是否已收到电子邮件,或想像其他符合您需要的对象. 搜索可能的ObjectClass列表,以查看您还可以使用什么.

For your users you could have something including "&(objectCategory=person)(objectClass=user)". You can also check that the AD objects has got an email or imagine anything else matching your needs depending on how the System Engineer set up the domain. Search for the list of possible ObjectClass to see what else you can use.

您在这里也有一个有趣的项目:http://www.codeproject.com/KB/system/activedirquery.aspx .

You also have an interesting project here : http://www.codeproject.com/KB/system/activedirquery.aspx.

可能可以使用这样的代码来推断您rlist中的哪些用户是真正的Active Directory用户.

Probably could use such a code to deduct which of the users in you rlist are really Active Directory users.

也就是说,在这里,我们仅讨论了使用System.DirectoryServices类和从Active Directory查询信息的问题.但是,您还谈论的是来自特定计算机的用户(嗯,在这里我实际上与您的要求有些混淆).所以 可能应该考虑改用WMI.您可能会在这里对此讨论感兴趣:http://bytes.com/topic/c-sharp/answers/631036-getting-currently-logged-user .如果您足够好奇,您可能也想在这里逛一逛: http://www.codeproject. com/KB/system/WMIProviderExtensions.aspx =>这不符合您的需求.

That said, here, we only spoke about using System.DirectoryServices classes and query information from Active Directory. But you are also talking about users from a specific machine (well, here I'm actually a little bit confuse with your requirements). So probably should else think about using WMI instead. You will perhaps be interested in this discussion here :http://bytes.com/topic/c-sharp/answers/631036-getting-currently-logged-user. If you are curious enought you may want to have a lokk here as well : http://www.codeproject.com/KB/system/WMIProviderExtensions.aspx => this one doesn't match your needs.

现在,当您询问"时,是否有一种方法可以使我仅获得实际登录的用户?控制台?",我认为与上面显示的代码有点不同.什么是 控制台?您是在谈论让当前Web应用程序中的所有用户登录吗?如果是,我可能会使用事件处理程序Session_Start和Session_End来维护自定义列表,而不是上面的所有内容.

Now, when you ask "Is there a way in which I can get only the users who actually log in to the  console?", I think it is a little bit different with the code you show above. What is the console ? Are you talking about getting all the user logged currently in a WebApplication ? If yes, I would probably use the event handlers Session_Start and Session_End to maintain a custom list instead all above.


这篇关于吸引系统用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:12