获取域的可分辨名称的示例代码
本主题包含一个代码示例,该代码示例将使用无服务器绑定,获取获取本地计算机是其成员的域的可分辨名称。
以下 Visual Basic 代码示例将使用无服务器绑定,获取本地计算机是其成员的域的可分辨名称。
Dim rootDSE As IADs
Dim DistinguishedName As String
Set rootDSE = GetObject("LDAP://rootDSE")
DistinguishedName = "LDAP://" & rootDSE.Get("defaultNamingContext")
以下 C# 代码示例将使用无服务器绑定,获取本地计算机是其成员的域的可分辨名称。
DirectoryEntry RootDirEntry = new DirectoryEntry("LDAP://RootDSE");
Object distinguishedName = RootDirEntry.Properties["defaultNamingContext"].Value;
以下 C/C++ 代码示例将使用无服务器绑定,获取本地计算机是其成员的域的可分辨名称。
IADs *pads;
hr = ADsGetObject( L"LDAP://rootDSE",
IID_IADs,
(void**)&pads);
if(SUCCEEDED(hr))
{
VARIANT var;
VariantInit(&var);
hr = pads->Get(CComBSTR("defaultNamingContext"), &var);
if(SUCCEEDED(hr))
{
if(VT_BSTR == var.vt)
{
wprintf(var.bstrVal);
}
VariantClear(&var);
}
pads->Release();
}