/*--------------------------------------------------------------------------
---
Constants for type of computer
----------------------------------------------------------------------------
--*/
&GLOB SV_TYPE_WORKSTATION 1
&GLOB SV_TYPE_SERVER 2
&GLOB SV_TYPE_SQLSERVER 4
&GLOB SV_TYPE_DOMAIN_CTRL 8
&GLOB SV_TYPE_DOMAIN_BAKCTRL 16
&GLOB SV_TYPE_TIME_SOURCE 32
&GLOB SV_TYPE_AFP 64
&GLOB SV_TYPE_NOVELL 128
&GLOB SV_TYPE_DOMAIN_MEMBER 256
&GLOB SV_TYPE_PRINTQ_SERVER 512
&GLOB SV_TYPE_DIALIN_SERVER 1024
&GLOB SV_TYPE_XENIX_SERVER 2048
&GLOB SV_TYPE_SERVER_UNIX 2048
&GLOB SV_TYPE_NT 4096
&GLOB SV_TYPE_WFW 8192
&GLOB SV_TYPE_SERVER_MFPN 16384
&GLOB SV_TYPE_SERVER_NT 32768
&GLOB SV_TYPE_POTENTIAL_BROWSER 65536
&GLOB SV_TYPE_BACKUP_BROWSER 131072
&GLOB SV_TYPE_MASTER_BROWSER 262144
&GLOB SV_TYPE_DOMAIN_MASTER 524288
&GLOB SV_TYPE_SERVER_OSF 1048576
&GLOB SV_TYPE_SERVER_VMS 2097152
&GLOB SV_TYPE_WINDOWS 4194304
&GLOB SV_TYPE_ALTERNATE_XPORT 536870912
&GLOB SV_TYPE_LOCAL_LIST_ONLY 1073741824
&GLOB SV_TYPE_DOMAIN_ENUM 2147483648
&GLOB SV_TYPE_ALL 65535
/* ------------------------------------------------
Structured used by NetServerEnum
--------------------------------------------------*/
/**********************************
Private Type SERVER_INFO_101
wki101_platform_id As Long
wki101_servername As Long
wki101_langroup As Long
wki101_ver_major As Long
wki101_ver_minor As Long
wki101_lanroot As Long
End Type
*******************************/
/*------------------------------------------------
Network API declarations
------------------------------------------------*/
PROCEDURE NetServerEnum EXTERNAL "Netapi32.dll":
define input parameter lpServerName as long. /* pointer to string
containing the name of the remote server */
define input parameter dwLevel as long. /* Specifis the
information level of the data. */
define output parameter lpServerInfo as long. /* pointer to a buffer
which contains the SERVER_INFO, level (100 or 101) */
define input parameter dwPrefMaxLen as long. /* Perfered max len of
returned data. If this is max_perfered_length,
the function will allocate the amount of memory needed for the data */
define output parameter dwEntriesRead as long. /* pointer to dword
value that receives the number of entries read */
define output parameter dwTotalEntries as long. /* pointer to a dword
value that receives the total number of visible
servers and workstations on the network */
define input parameter dwServerType as long. /* server type */
define input parameter lpDomain as long. /* pointer to string
containing domain */
define input parameter ResumeHandle as long. /* reserved, must be 0.
*/
define return parameter iRetCode as long. /* non 0 on success */
END.
PROCEDURE NetApiBufferFree EXTERNAL "Netapi32.dll":U:
define input parameter lpServerInfo as long. /* pointer to a buffer
that was previously returned by another network
mamagement function. */
define return parameter iRetCode as long.
END.
PROCEDURE GetComputerNameA EXTERNAL "kernel32.dll":U:
define output parameter lpBuffer AS char.
define input-output parameter nSize AS LONG.
define return parameter intResult AS SHORT.
END PROCEDURE.
PROCEDURE WideCharToMultiByte EXTERNAL "KERNEL32.dll":
define input parameter uCodePage as long. /* code page
*/
define input parameter dwFlags as long. /* performance and
mapping flags */
define input parameter lpWideCharStr as long. /* address of
wide-character string */
define input parameter cbWideChar as long. /* number of
characters in string, if -1 is calculated on the fly */
define input parameter lpMultiByteStr as long. /* address of buffer
for new string */
define input parameter cbMultiByte as long. /* size of buffer */
define input parameter lpDefaultChar as long. /* address of default
for unmappable characters */
define input parameter lpUsedDefaultChar as long. /* address of flag set
when default char is used */
define return parameter iRetCode as long. /* if successful,
number of bytes written to the lpMultiByteStr buffer, else 0 */
END.
Function GetComputerName()
RETURNS CHARACTER
( /* parameter-definitions */ ) :
/*------------------------------------------------------------------------
Function: GetComputerName
Description: Returns a character string of the computer name.
History:
------------------------------------------------------------------------*/
&SCOPE MAX_COMPUTERNAME_LENGTH 16
def var iResult as integer no-undo.
def var iBufferSize as integer no-undo init {&MAX_COMPUTERNAME_LENGTH}.
def var iBuffer as integer no-undo.
def var cComputerName as char no-undo.
cComputerName = fill(' ', {&MAX_COMPUTERNAME_LENGTH}).
run GetComputerNameA (output cComputerName,
input-output iBufferSize,
output iResult).
if iResult <> 1 then
do:
message 'Unable to determine local computer name.':T70 view-as alert-box
error.
return "":U.
end.
return ( cComputerName ).
END FUNCTION.
define variable cLocalComputerName as char no-undo.
define variable iRetCode as integer no-undo.
define variable iOffset as integer no-undo.
define variable i as integer no-undo.
define variable iTotalEntries as integer no-undo.
define variable iEntriesRead as integer no-undo.
define variable iServerInfo as integer no-undo.
define variable lpServerInfo as memptr no-undo.
define variable lpServerName as memptr no-undo.
cLocalComputerName = GetComputerName().
RUN NetServerEnum( input 0, /* pointer to
string containing the server name to execute this function on */
input 101, /* SERVER_INFO
to return, 100 or 101 */
output iServerInfo, /* pointer to
the SERVER_INFO Structure base on 100 or 101 */
input {&MAX_PREFERRED_LENGTH}, /* max
perfered lenth, if set to -1 it will allocate necessary space */
output iEntriesRead, /* total
number of entries returned */
output iTotalEntries, /* total
number of entries */
input {&SV_TYPE_DOMAIN_CTRL}, /* server type
to enumerate */
/* {&SV_TYPE_ALL}, */ /* list all
machines on network */
input 0, /* ptr to
string containing Domain Name */
input 0, /* reserved,
must be 0 */
output iRetCode). /* non 0 on
success */
set-pointer-value(lpServerInfo) = iServerInfo.
iOffSet = 1.
set-size(lpServerName) = 0.
set-size(lpServerName) = 512.
do i = 1 to iEntriesRead:
run WideCharToMultiByte( input 0, /* use ANSI code page */
input 0, /* flags that specify the
handling of unmapped characters */
input get-long(lpServerInfo, iOffset + 4), /*
pointer to wide-character string (unicode) */
input -1, /* count of bytes of the
wide-character string, if -1 calculate on the fly */
input get-pointer-value(lpServerName), /*
address of buffer for new string */
input get-size(lpServerName),
input 0,
input 0,
output iRetCode).
if iRetCode <> 0 then
phSelectionList:ADD-LAST(get-string(lpServerName,1) + (if
cLocalComputerName = get-string(lpServerName,1) then ' (Local)':U else
'':U)).
iOffset = iOffset + 24.
end.
RUN NetApiBufferFree( input get-pointer-value(lpServerInfo),
output iRetCode ).
set-size(lpServerName) = 0.