如何在 ASP.NET 中列出 Windows 用户和组?

How to list Windows users and groups in ASP.NET?(如何在 ASP.NET 中列出 Windows 用户和组?)
本文介绍了如何在 ASP.NET 中列出 Windows 用户和组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 ASP.NET 网站项目,我需要列出 Windows 系统上的所有用户及其组.我已将身份模拟设置为 true,并在 web.config 中提供了管理员的用户名和密码.我从哪里开始?

I have a ASP.NET Website project and I need to list all the users and their groups on my Windows system. I have set the identity impersonation to true and provided the username and password of the admin in the web.config. Where do I start?

提前致谢.

更新:

我现在有以下代码 -

    var machine = new DirectoryEntry("WinNT://<IP ADDRESS>");
                foreach (DirectoryEntry child in machine.Children)
                {
                   // get the child's group(s).
                }

调试的时候可以看到machine.Children里面的用户列表.如何找到该用户所属的组?

When I debug, I can see the list of users in machine.Children. How do I find the group(s) that this user belongs to?

推荐答案

您可能希望从 .net 中的 DirectoryEntry 和 Active Directory 支持开始.

You probably want to start with the DirectoryEntry and Active Directory support in .net.

这里有一个很好的资源:http://www.codeproject.com/KB/系统/everythingInAD.aspx

Here's a good resource: http://www.codeproject.com/KB/system/everythingInAD.aspx

本地访问类似,即使您不在域中:

Local access is similar, even if you're not in a domain:

DirectoryEntry localMachine = new DirectoryEntry("WinNT://" +
               Environment.MachineName);
DirectoryEntry admGroup = localMachine.Children.Find("administrators",
               "group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members) {
  DirectoryEntry member = new DirectoryEntry(groupMember);
  //...
}

这篇关于如何在 ASP.NET 中列出 Windows 用户和组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I add my application in the Default Programs list of Windows Vista/7?(如何将我的应用程序添加到 Windows Vista/7 的默认程序列表中?)
FileSystemWatcher and windows 7(FileSystemWatcher 和 Windows 7)
ClickOnce application does not start through Process.Start(quot;x.abcquot;) with *.abc associated to the ClickOnce application(ClickOnce 应用程序不通过 Process.Start(“x.abc) 启动,其中 *.abc 与 ClickOnce 应用程序关联) - IT屋-程序员软件开发
How can I detect wallpaper changing as a result of the Windows 7 slideshow?(如何检测由于 Windows 7 幻灯片放映而导致的墙纸变化?)
Change printer default paper size(更改打印机默认纸张大小)
Change default audio device on Windows 7(更改 Windows 7 上的默认音频设备)