简体   繁体   English

Delphi-如何获取我的完整域名

[英]Delphi- How to get my full domain name

In my program I am trying to retrieve the domain name of the current machine. 在我的程序中,我试图检索当前机器的域名。 i found some code that people wrote in forums but they all seem to work partially. 我找到了一些人们在论坛中写的代码,但它们似乎都是部分工作的。

what i mean is that my domain name is something like 'mydomain.mydomain11.com' and when trying to retrieve the domain name i always get only 'mydomain' instead of 'mydomain.mydomain11' 我的意思是我的域名是'mydomain.mydomain11.com',当我尝试检索域名时,我总是只得到'mydomain'而不是'mydomain.mydomain11'

I also tried usng the 'GetEnvironmentVariable' function which returns the same thing. 我也尝试使用'GetEnvironmentVariable'函数返回相同的东西。

If possible, i would like to know how can i retrieve the full path. 如果可能的话,我想知道如何检索完整路径。

my final goal is to query active directory using LDAP protocol, so it will really help to know how can chunk the domain path to something like : 我的最终目标是使用LDAP协议查询活动目录,因此它将真正有助于了解如何将域路径分块为:

CN=Users,DC=mydomain,DC=mydomain11,DC=com

but getting my full domain name will do for now.. 但获取我的完整域名现在可以做..

You can use the GetComputerNameEx function with the ComputerNamePhysicalDnsDomain parameter: 您可以将GetComputerNameEx函数与ComputerNamePhysicalDnsDomain参数一起使用:

The name of the DNS domain assigned to the local computer. 分配给本地计算机的DNS域的名称。 If the local computer is a node in a cluster, lpBuffer receives the DNS domain name of the local computer, not the name of the cluster virtual server.` 如果本地计算机是群集中的节点,则lpBuffer将接收本地计算机的DNS域名,而不是群集虚拟服务器的名称。

If your goal is to connect to LDAP to search objects in the directory the usual approach is to connect to RootDSE. 如果您的目标是连接到LDAP以搜索目录中的对象,则通常的方法是连接到RootDSE。 Here is an example . 这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM