Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Jan 20, 2001

GetPDCName - The name of the Primary Domain Controller

Private Declare Function NetGetDCName Lib "netapi32.dll" (strServerName As Any, _
    strDomainName As Any, pBuffer As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32.dll" (buffer As Any) As _
    Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As _
    Any, source As Any, ByVal bytes As Long)

' Return the name of the Primary Domain Controller (PDC)
'
' server names are preceded by a double slash

Function GetPDCName() As String
    Dim lpBuffer As Long
    Dim buffer As String
    
    If NetGetDCName(vbNullString, vbNullString, lpBuffer) = 0 Then
        ' a zero return value means success
        buffer = Space$(128)
        ' copy into local buffer
        CopyMemory ByVal StrPtr(buffer), ByVal lpBuffer, LenB(buffer)
        ' trim excess chars
        GetPDCName = Left$(buffer, InStr(buffer & vbNullChar, vbNullChar) - 1)
        ' release memory
        NetApiBufferFree lpBuffer
    End If

End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap