Retrieve List Of Servers On All Ports
Domino servers from all ports. It returns a Variant containing an array of
server names in canonical format that you can iterate through to suit your
needs.
For example, to display a list of common names of all servers in a messagebox,
you can use the following button code:
Sub Click(Source As Button)
Dim n As NotesName
Dim sMsg$
Dim vServerList
' get list of servers
vServerList=GetServerList()
sMsg$="Server List:" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
' loop over server list and build a string we can display
Forall s In vServerList
Set n = New NotesName(s)
sMsg$=sMsg$ & n.Common & Chr(13) & Chr(10)
End Forall
' show the list in a messagebox
Msgbox sMsg$, 0, "Server List Demo"
End Sub
' Notes API declares and constants
Declare Function NSGetServerList% Lib "nnotes" (Byval dwPortName&,
nRetServerTextList%)
Declare Function ListGetText% Lib "nnotes" (Byval dwList&, Byval
nPrefixDataType%, Byval nEntryNumber%, dwRetTextPointer&, nRetTextLength%)
Declare Function OSTranslate% Lib "nnotes" (Byval nTranslateMode%, Byval
dwIn&, Byval nLength%, Byval lpszOut$, Byval nOutLength%)
Declare Function OSLockObject& Lib "nnotes" (Byval nHandle%)
Declare Function OSUnlockObject% Lib "nnotes" (Byval nHandle%)
Declare Function OSMemFree% Lib "nnotes" (Byval nHandle%)
Const OS_TRANSLATE_LMBCS_TO_NATIVE = 1
Const MAX_SERVER_NAME = 256
Function GetServerList() As Variant
Dim lpszServer$
Dim szArray() As String
Dim hList%, nStatus%, nCount%, nLength%
Dim dwList&, dwHold&
' get a list of known servers on all ports
nStatus%=NSGetServerList(0, hList%)
' be sure our API call returned a handle to our list buffer
If nStatus%=0 And hList% <> 0 Then
' initialize our results array
Redim szArray(0)
' lock down our memory handle
dwList&=OSLockObject(hList%)
Do While nStatus%=0
' get a server in the list
nStatus%=ListGetText(dwList&, 0, nCount%, dwHold&, nLength%)
If nStatus%=0 And nLength%>0 Then
' intialize the string to pass to the API
lpszServer$=Space$(nLength%)
' translate the results to the native charset
Call OSTranslate(OS_TRANSLATE_LMBCS_TO_NATIVE, dwHold&, nLength%, lpszServer$,
MAX_SERVER_NAME)
'populate an array with the results
Redim Preserve szArray(nCount)
szArray(nCount)=lpszServer$
End If
nCount=nCount+1
Loop
' free our lock on the list
Call OSUnlockObject(hList%)
' free the handle allocated by NSGetServerList
Call OSMemFree(hList%)
End If
' return results to caller
GetServerList=szArray
End Function