使用C#获取远程计算机的详细信息 [英] Getting detail of a remote computer using C#
问题描述
如果我知道它的IP地址,我想获得远程计算机的详细信息。
我能够使用系统的GetHostEntry()方法知道计算机名称。通过传递远程计算机的IP地址的网络类
但是我需要了解远程计算机的更多细节,例如操作系统名称,操作系统版本,用户名等
请提供一些C#代码 NOT 包括SELECT * FROM Win32_OperatingSystem,如程序。
如果可能的话,我想知道一个win32 API。
I want to get detail of a remote computer if i know its IP address.
I am able to know computer name using GetHostEntry() method of system.net class by passing IP address of a remote computer
but i need to know more detail of a remote computer like OS name, OS version, UserNames etc
Please give some C# code which do NOT include "SELECT * FROM Win32_OperatingSystem" like program.
I like to know a win32 API for that if possible.
推荐答案
你打折了唯一的方法获取此信息。您必须为此使用WMI,并且需要具有目标计算机权限的用户帐户才能读取此信息。
You discounted the only way you''re going to get this information. You have to use WMI for this and need a user account that has permissions on the target machine to read this information.
如果您想知道工作组计算机名称,那么代码将是
If you want to know the workgroup computer name then code will be
var de = new DirectoryEntry("WinNT://" + workgroupName);
foreach (DirectoryEntry c in de.Children)
{
Console.WriteLine(c.Name);
}
如果您想知道域名计算机名称列表,那么它将是
If you want to know the list of domain computer name then it will be
var de = new DirectoryEntry("LDAP://" + domainName);
de.Children.SchemaFilter.Add("computer");
foreach (DirectoryEntry c in de.Children)
{
Console.WriteLine(c.Name);
}
只需要从GAC(框架dll)中引用System.DirectoryServices组件。
Just you need to take reference of System.DirectoryServices component from GAC(framework dll).
这篇关于使用C#获取远程计算机的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!