devxlogo

GetPDCName – The name of the Primary Domain Controller

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 LongPrivate Declare Function NetApiBufferFree Lib "netapi32.dll" (buffer As Any) As _    LongPrivate 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 slashFunction 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 IfEnd Function

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist