Click to See Complete Forum and Search --> : Get Server Name


jen
January 26th, 2000, 01:09 AM
Hi!
How can I get the servername?
I guess it is with an API but can't find the right one.

Thanks in advance
jen

Lothar Haensler
January 26th, 2000, 01:15 AM
what kind of server are you trying to get?
- NetServerEnum allows you to enumerate all
servers.
- NetGetDCName retrieves the name of the domain controller

jen
January 26th, 2000, 04:09 AM
Hi Lothar and thanks for your quick answer!
I want the Domain Controller but when I search my Win32 via API viewer I can't find this api. What am I doing wrong?
(I'm using NT 4.0)
jen

Lothar Haensler
January 26th, 2000, 04:21 AM
>What am I doing wrong?
Nothing. the API Viewer does not list that function.


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





parts of that code abopted from Karl Peterson...