by murali bala (7 Submissions)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 15th November 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Get your Server name - the easy way
API Declarations
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 GetServername(bufptr)
NetApiBufferFree bufptr
End Sub
Private Function GetServername(ByVal l As Long) As String
Dim bbuffer() As Byte
Dim nLen As Long
nLen = lstrlenW(l) * 2
If nLen Then
ReDim bbuffer(0 To (nLen - 1)) As Byte
CopyMemory bbuffer(0), ByVal l, nLen
GetServername = bbuffer
End If
End Function