怎么获取域用户的登录名

youzi8800 2011-08-25 04:03:23
怎么通过程序获取所有域用户的登陆账号(是登陆账号不是显示的用户名)
...全文
235 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
萧炎 2011-08-26
  • 打赏
  • 举报
回复
foreach(DirectoryEntry mydirchild in dir.Children)
LZ你将dir.Children改称dir试试 我以前做的是获取了当前用户
youzi8800 2011-08-26
  • 打赏
  • 举报
回复
DirectoryEntry dir = new DirectoryEntry(path,username,password);
foreach(DirectoryEntry mydirchild in dir.Children)
{
Response.Write(mydirchild.Username+ " <br/> ");
}

这样取出来的是当前用户等登陆账号,不是取出所有用户的登陆账号
还想懒够 2011-08-25
  • 打赏
  • 举报
回复
DirectoryEntrty来获取
萧炎 2011-08-25
  • 打赏
  • 举报
回复
DirectoryEntry dir = new DirectoryEntry(path,username,password);
foreach(DirectoryEntry mydirchild in dir.Children)
{
Response.Write(mydirchild.Username+ " <br/> ");
}
youzi8800 2011-08-25
  • 打赏
  • 举报
回复
不管有没有登陆域,只要在域的Users中存在就获取出来
youzi8800 2011-08-25
  • 打赏
  • 举报
回复
肯能我描述的不够清楚, 我想要当前计算机所在域中所有域用户的登陆账号

现在条件是我能通过域名,管理员账号和密码访问域服务器,能获取到所有用户的显示名称,而不能获取到所有用户在登陆域时候的登陆名称
心灵彩虹 2011-08-25
  • 打赏
  • 举报
回复
Ensure your project has referenced dll "System.Management", then csharp codes as below:



using System.Diagnostics;

using System.Management;



namespace WorkRecord

{

class CurrentUser

{

public static string GetCurrentUser()

{

string currentUser = null;



foreach (Process p in Process.GetProcesses())

{

currentUser = GetProcessUserName(p.Id);

if (currentUser != "SYSTEM" && currentUser != null && currentUser != string.Empty)

break;

}

return currentUser;

}



private static string GetProcessUserName(int pID)

{



string theUser = null;



SelectQuery query1 = new SelectQuery("Select * from Win32_Process WHERE processID=" + pID);

ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(query1);



try

{

foreach (ManagementObject disk in searcher1.Get())

{

ManagementBaseObject inPar = null;

ManagementBaseObject outPar = null;



inPar = disk.GetMethodParameters("GetOwner");

outPar = disk.InvokeMethod("GetOwner", inPar, null);

theUser = outPar["User"].ToString();

break;

}

}

catch

{

theUser = "SYSTEM";

}



return theUser;

}



}

}
dongxiao0517 2011-08-25
  • 打赏
  • 举报
回复
public static class Comm
{
public static string username { get; set; }
}
登录成功后执行: Comm.username = txt_username.text。
txt_username.text为输入的用户名

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧