.NET 中机器的域名? [英] Machine's domain name in .NET?

查看:22
本文介绍了.NET 中机器的域名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须有一个简单的方法来做到这一点,我不敢相信没有.我已经通过网络扫描并找到了 20 种不同的方法来查找当前用户所在的域,但没有一种方法可以获取当前计算机的域(或工作组).

There gotta be an easy way to do this, I can't believe there's none. I have scanned through net and found, like, 20 different methods to find in which domain current user is, but none to get domain (or workgroup) of current machine.

在非托管 C++ 中,这是通过以下方式检索的:

In unmanaged c++ this is retrieved by:

WKSTA_INFO_100 *buf;
NetWkstaGetInfo(NULL, 100, (LPBYTE*)buf);
domain_name = pBuf->wki100_langroup;

如果有办法在托管 C# 中本地获取相同的信息,有人可以帮助我吗?

can someone help me, if there's a way to get same info in managed C# natively?

各位,请阅读问题.我不是在寻找用户域名.

推荐答案

要获取运行程序的系统的当前域,您可以使用System.DirectoryServices.ActiveDirectory.Domain.

To get the current domain of the system on which your progam is running you can use System.DirectoryServices.ActiveDirectory.Domain.

Domain domain = Domain.GetComputerDomain();
Console.WriteLine( domain.Name );

这篇关于.NET 中机器的域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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