如何找到网络机器名和登录该计算机的用户? [英] How to Find Network Machine names and the user logged in that machine?

查看:215
本文介绍了如何找到网络机器名和登录该计算机的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一定要找到计算机名以及登录到机器的用户名。

I have to find the machine names and the user names of those logged in to the machines.

  I have Updated My answer please see my answer !!!!

 NetworkBrowser nb = new NetworkBrowser();
 IPHostEntry ip = Dns.GetHostEntry(Dns.GetHostName());
 foreach (string pc in nb.getNetworkComputers())
 {
      cmbNetworkComputers.Items.Add(pc);
 }
 cmbNetworkComputers.SelectedIndex = 0;

上面的代码检索机的名字,我怎么能得到用户名?

The above code retrieves the machine names, how can I get the user names?

推荐答案

一看便知在 - 的如何获得本地网络上的计算机列表 - ?有关如何获取的计算机列表指针

See the answer at - How get list of local network computers? - for pointers on how to get a list of computers.

当你有。列出您可以使用WMI来查询计算机的登录用户

When you have the list you can use the WMI to query the computers for logged on users.

string comp = "Computer";
ConnectionOptions options = new ConnectionOptions();
//user (domain or local) with sufficient privileges to access the remote system through WMI
options.Username = "Usersname"; 
options.Password = "Password";
ManagementScope s = new ManagementScope(string.Format(@"\\{0}\root\cimv2", comp), options);

ManagementPath p = new ManagementPath(string.Format("Win32_ComputerSystem.Name='{0}'", comp));

using(ManagementObject cs = new ManagementObject (s, p, null ))
{
    cs.Get();
    Console.WriteLine(cs["UserName"]);
}

这篇关于如何找到网络机器名和登录该计算机的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆