L
Luke Morehead
I'm trying to use DsEnumerateDomainTrusts to generate a
list of trusted domains in VB.NET. The code I've listed
below generates the error, "An unhandled exception of
type 'System.NullReferenceException' occurred in
NetDisco.exe. Additional information: Object reference
not set to an instance of an object." Any ideas on how
to call this API function properly from VB.NET? Thank
you.
Luke Morehead
=-=-=-=-=-=-=-=-
Private Declare Function DsEnumerateDomainTrusts
Lib "netapi32.dll" Alias "DsEnumerateDomainTrustsW" ( _
ByVal lpszServerName As IntPtr, _
ByVal luFlags As UInt64, _
ByRef lpBuffer As IntPtr, _
ByRef pluDomainCount As IntPtr) As Integer
Private Const DS_DOMAIN_DIRECT_OUTBOUND = 2
Private Const NERR_Success = 0
Private Structure DS_DOMAIN_TRUSTS
Dim lpszNetBIOSDomainName As IntPtr
Dim lpszDNSDomainName As IntPtr
Dim luFlags As UInt64
Dim luParentIndex As UInt64
Dim luTrustType As UInt64
Dim luTrustAttributes As UInt64
Dim pSID As IntPtr
Dim gGUID As Guid
End Structure
Private Sub GetTrustedDomains(ByVal strDomainController
as String)
Dim lpDomainCount As IntPtr
Dim lpBuffer as IntPtr = IntPtr.Zero
Dim intResult as Integer
intResult = DsEnumerateDomainTrusts _
(Marshal.StringToHGlobalUni(strDomainController),
_
Convert.ToUInt64(DS_DOMAIN_DIRECT_OUTBOUND), _
lpBuffer, lpDomainCount)
If intResult = NERR_Success Then
Dim DomainTrusts As DS_DOMAIN_TRUSTS
Dim intDomainCount As Integer
Dim strTrustedDomain As String
intDomainCount = lpDomainCount.ToInt32
For i = 1 To intDomainCount
DomainTrusts = CType(Marshal.PtrToStructure _
(lpBuffer, GetType(DS_DOMAIN_TRUSTS)), _
DS_DOMAIN_TRUSTS)
Console.WriteLine("Trusted Domain: " & _
Marshal.PtrToStringUni
(DomainTrusts.lpszNetBIOSDomainName)
Next i
Else
Console.WriteLine("DsEnumerateDomainTrusts
failed: " _
& intResult)
End If
End Sub
list of trusted domains in VB.NET. The code I've listed
below generates the error, "An unhandled exception of
type 'System.NullReferenceException' occurred in
NetDisco.exe. Additional information: Object reference
not set to an instance of an object." Any ideas on how
to call this API function properly from VB.NET? Thank
you.
Luke Morehead
=-=-=-=-=-=-=-=-
Private Declare Function DsEnumerateDomainTrusts
Lib "netapi32.dll" Alias "DsEnumerateDomainTrustsW" ( _
ByVal lpszServerName As IntPtr, _
ByVal luFlags As UInt64, _
ByRef lpBuffer As IntPtr, _
ByRef pluDomainCount As IntPtr) As Integer
Private Const DS_DOMAIN_DIRECT_OUTBOUND = 2
Private Const NERR_Success = 0
Private Structure DS_DOMAIN_TRUSTS
Dim lpszNetBIOSDomainName As IntPtr
Dim lpszDNSDomainName As IntPtr
Dim luFlags As UInt64
Dim luParentIndex As UInt64
Dim luTrustType As UInt64
Dim luTrustAttributes As UInt64
Dim pSID As IntPtr
Dim gGUID As Guid
End Structure
Private Sub GetTrustedDomains(ByVal strDomainController
as String)
Dim lpDomainCount As IntPtr
Dim lpBuffer as IntPtr = IntPtr.Zero
Dim intResult as Integer
intResult = DsEnumerateDomainTrusts _
(Marshal.StringToHGlobalUni(strDomainController),
_
Convert.ToUInt64(DS_DOMAIN_DIRECT_OUTBOUND), _
lpBuffer, lpDomainCount)
If intResult = NERR_Success Then
Dim DomainTrusts As DS_DOMAIN_TRUSTS
Dim intDomainCount As Integer
Dim strTrustedDomain As String
intDomainCount = lpDomainCount.ToInt32
For i = 1 To intDomainCount
DomainTrusts = CType(Marshal.PtrToStructure _
(lpBuffer, GetType(DS_DOMAIN_TRUSTS)), _
DS_DOMAIN_TRUSTS)
Console.WriteLine("Trusted Domain: " & _
Marshal.PtrToStringUni
(DomainTrusts.lpszNetBIOSDomainName)
Next i
Else
Console.WriteLine("DsEnumerateDomainTrusts
failed: " _
& intResult)
End If
End Sub