GetServerName




Option Explicit

Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function NetGetDCName Lib "Netapi32.dll" (strServer As Any, strDomain As Any, bufptr As Long) As Long
Private Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Long) As Long


Private Sub Command1_Click()
Dim l As Long
Dim dc() As Byte
Dim bufptr As Long
l = NetGetDCName(ByVal 0&, _
ByVal 0&, _
bufptr)
MsgBox Pointer2stringw(bufptr)
NetApiBufferFree bufptr
End Sub


Private Function Pointer2stringw(ByVal l As Long) As String
Dim buffer() As Byte
Dim nLen As Long
nLen = lstrlenW(l) * 2
If nLen Then
ReDim buffer(0 To (nLen - 1)) As Byte
CopyMemory buffer(0), ByVal l, nLen
Pointer2stringw = buffer
End If
End Function










( getservername.html )- by Paolo Puglisi - Modifica del 17/12/2023