Results 1 to 2 of 2

Thread: [RESOLVED] DsGetDcName / Return Flag Integer back to Enum

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342

    Resolved [RESOLVED] DsGetDcName / Return Flag Integer back to Enum

    Hello, I am by no means a guru to API calls so this one took me a while to do but what I would like is take my Integer Value for FLAGS and break that back down into the individual flags (the enumeration). Is there an easy way to do this?
    vb Code:
    1. Imports System.Runtime.InteropServices
    2. Module Module1
    3.     Private Enum Flags As Integer
    4.         DS_FLAGS_NONE = &H0
    5.         DS_FORCE_REDISCOVERY = &H1
    6.         DS_DIRECTORY_SERVICE_REQUIRED = &H10
    7.         DS_DIRECTORY_SERVICE_PREFERRED = &H20
    8.         DS_GC_SERVER_REQUIRED = &H40
    9.         DS_PDC_REQUIRED = &H80
    10.         DS_BACKGROUND_ONLY = &H100
    11.         DS_IP_REQUIRED = &H200
    12.         DS_KDC_REQUIRED = &H400
    13.         DS_TIMESERV_REQUIRED = &H800
    14.         DS_WRITABLE_REQUIRED = &H1000
    15.         DS_GOOD_TIMESERV_PREFERRED = &H2000
    16.         DS_AVOID_SELF = &H4000
    17.         DS_ONLY_LDAP_NEEDED = &H8000
    18.         DS_IS_FLAT_NAME = &H10000
    19.         DS_IS_DNS_NAME = &H20000
    20.         DS_RETURN_DNS_NAME = &H40000000
    21.         DS_RETURN_FLAT_NAME = &H80000000
    22.     End Enum
    23.    
    24.  
    25.     Private Enum AddressTypes As UInteger
    26.         DS_INET_ADDRESS = 1
    27.         DS_NETBIOS_ADDRESS = 2
    28.     End Enum
    29.  
    30.     Sub Main()
    31.         Dim pDCI As IntPtr = IntPtr.Zero
    32.         Dim dcName As DOMAIN_CONTROLLER_INFO = Nothing
    33.  
    34.         Console.WriteLine("Enter the domain to query:")
    35.         Dim Domain As String = Console.ReadLine
    36.         If Domain = "" Then End
    37.  
    38.         Dim retval As Integer = DsGetDcName("", Domain, 0, "", Flags.DS_FLAGS_NONE, pDCI)
    39.  
    40.         If retval = 0 Then
    41.             NetApiBufferFree(pDCI)
    42.             dcName = Marshal.PtrToStructure(pDCI, GetType(DOMAIN_CONTROLLER_INFO))
    43.             Console.WriteLine("Domain Controller Name:         " & dcName.DomainControllerName)
    44.             Console.WriteLine("Domain Controller Address:      " & dcName.DomainControllerAddress)
    45.             Console.WriteLine("Domain Controller Address Type: " & dcName.DomainControllerAddressType.ToString)
    46.             Console.WriteLine("Domain Guid:                    " & dcName.DomainGuid.ToString)
    47.             Console.WriteLine("Domain Name:                    " & dcName.DomainName)
    48.             Console.WriteLine("DNS Forest Name:                " & dcName.DnsForestName)
    49.             Console.WriteLine("Domain Controller Site Name:    " & dcName.DcSiteName)
    50.             Console.WriteLine("Client Site Name:               " & dcName.ClientSiteName)
    51.             Console.WriteLine("Flags Passed:                   " & dcName.Flags)
    52.             Console.WriteLine()
    53.             Console.WriteLine("Any key to exit")
    54.             Console.ReadKey()
    55.         Else
    56.             Stop
    57.         End If
    58.  
    59.     End Sub
    60.  
    61.     Private Structure DOMAIN_CONTROLLER_INFO
    62.         <MarshalAs(UnmanagedType.LPWStr)> Dim DomainControllerName As String
    63.         <MarshalAs(UnmanagedType.LPWStr)> Dim DomainControllerAddress As String
    64.         <MarshalAs(UnmanagedType.U4)> Dim DomainControllerAddressType As AddressTypes
    65.         Dim DomainGuid As System.Guid
    66.         <MarshalAs(UnmanagedType.LPWStr)> Dim DomainName As String
    67.         <MarshalAs(UnmanagedType.LPWStr)> Dim DnsForestName As String
    68.         <MarshalAs(UnmanagedType.U4)> Dim Flags As Flags
    69.         <MarshalAs(UnmanagedType.LPWStr)> Dim DcSiteName As String
    70.         <MarshalAs(UnmanagedType.LPWStr)> Dim ClientSiteName As String
    71.     End Structure
    72.  
    73.     <DllImport("Netapi32.dll", CharSet:=CharSet.Unicode)> Private Function DsGetDcName( _
    74.     ByVal ComputerName As String, _
    75.     ByVal DomainName As String, _
    76.     ByVal DomainGuid As Integer, _
    77.     ByVal SiteName As String, _
    78.     ByVal Flags As Flags, _
    79.     ByRef pDOMAIN_CONTROLLER_INFO As IntPtr) As Integer
    80.     End Function
    81.  
    82.     <DllImport("Netapi32.dll")> Private Function NetApiBufferFree(ByRef buffer As IntPtr) As Integer
    83.     End Function
    84. End Module
    So, if I query a domain I may get an integer returned like -2147483139 and I would like to know what FLAGS that equals to.
    Thanks!!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] DsGetDcName / Return Flag Integer back to Enum

    This thread is marked resolved with no posted resolution.

    Is it resolved?

    If so, what was the resolution? It might help others with the same or similiar problem.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width