| Platform SDK: Active Directory, ADSI, and Directory Services |
The following code fragment contains a function that reads the ntMixedDomain property of a domain and determines the operation mode:
HRESULT GetDomainMode(IADs *pDomain, BOOL *bIsMixed)
{
HRESULT hr = E_FAIL;
VARIANT var;
if (pDomain)
{
VariantClear(&var);
//Get the ntMixedDomain attribute
LPOLESTR szAttribute = L"ntMixedDomain";
hr = pDomain->Get(szAttribute,&var);
if (SUCCEEDED(hr))
{
//Type should be VT_I4.
if (var.vt==VT_I4)
{
//Zero means native mode.
if (var.lVal == 0)
*bIsMixed = FALSE;
//One means mixed mode.
else if (var.lVal == 1)
*bIsMixed = TRUE;
else
hr=E_FAIL;
}
}
VariantClear(&var);
}
return hr;
}
The script reads the ntMixedDomain property of a domain and determines the operation mode:
'Example: Detects if a domain is in mixed mode or native mode
Dim IADsRootDSE As IADs
Dim IADsDomain As IADs
On Error Resume Next
sComputer = InputBox("This script detects if a Windows 2000 domain is running in mixed or native mode." & vbCrLf & vbCrLf & "Specify the domain name or the name of a domain controller in the domain :")
sPrefix = "LDAP://" & sComputer & "/"
'''''''''''''''''''''''''''''''''''''''
'Bind to a ds server
'''''''''''''''''''''''''''''''''''''''
Set IADsRootDSE = GetObject(sPrefix & "rootDSE")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on GetObject method"
Exit Sub
End If
sDomain = IADsRootDSE.Get("defaultNamingContext")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on Get method"
Exit Sub
End If
Set IADsDomain = GetObject(sPrefix & sDomain)
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on GetObject method"
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''
'Get ntMixedDomain property
'''''''''''''''''''''''''''''''''''''''
sMode = IADsDomain.Get("ntMixedDomain")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on Get ntMixedDomain property"
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''
'Get name property
'''''''''''''''''''''''''''''''''''''''
sName = IADsDomain.Get("name")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on Get name property"
Exit Sub
End If
If (sMode = 0) Then
sModeString = "Native"
ElseIf (sMode = 1) Then
sModeString = "Mixed"
Else
BailOnFailure sMode, "Invalid ntMixedDomain value: " & sMode
Exit Sub
End If
strText = "The domain " & sName & " is in " & sModeString & " mode."
MsgBox strText
'''''''''''''''''''''''''''''''''''''''
'Display subroutines
'''''''''''''''''''''''''''''''''''''''
Sub show_groups(strText, strName)
MsgBox strText, vbInformation, "Groups on " & strName
End Sub
Sub BailOnFailure(ErrNum, ErrText) strText = "Error 0x" & Hex(ErrNum) & " " & ErrText
MsgBox strText, vbInformation, "ADSI Error"
WScript.Quit
End Sub