NET_API_STATUS NetServerEnum( LPTSTR servername,
DWORD level,
LPBYTE *bufptr,
DWORD prefmaxlen,
LPDWORD entriesread,
LPDWORD totalentries,
DWORD servertype,
LPTSTR domain,
LPDWORD resume_handle
);
ParametersservernamePointer to a Unicode string containing the name of the remote server on which the function is to execute. A NULL pointer or string specifies the local computer.levelSpecifies one of the following values to return the level of information provided.Value Meaning
100 The bufptr parameter points to an array of SERVER_INFO_100 structures.
101 The bufptr parameter points to an array of SERVER_INFO_101 structures.
bufptrPointer to the buffer in which the data set with the level parameter is stored. prefmaxlenPreferred maximum length, in 8-bit bytes of returned data.entriesreadOn return, the actual enumerated element count is located in the doubleword pointed to by entriesread.totalentriesReturns the total number of visible servers and workstations on the network. servertypeA DWORD mask that filters server entries to return from the enumeration. The defined mask bits specify:Symbolic constant Value Meaning
SV_TYPE_WORKSTATION 0x00000001 All LAN Manager workstations
SV_TYPE_SERVER 0x00000002 All LAN Manager servers
SV_TYPE_SQLSERVER 0x00000004 Any server running with Microsoft SQL Server
SV_TYPE_DOMAIN_CTRL 0x00000008 Primary domain controller
SV_TYPE_DOMAIN_BAKCTRL 0x00000010 Backup domain controller
SV_TYPE_TIMESOURCE 0x00000020 Server running the Timesource service
SV_TYPE_AFP 0x00000040 Apple File Protocol servers
SV_TYPE_NOVELL 0x00000080 Novell servers
SV_TYPE_DOMAIN_MEMBER 0x00000100 LAN Manager 2.x Domain Member
SV_TYPE_LOCAL_LIST_ONLY 0x40000000 Servers maintained by the browser. See the following Res section.
SV_TYPE_PRINT 0x00000200 Server sharing print queue
SV_TYPE_DIALIN 0x00000400 Server running dial-in service
SV_TYPE_XENIX_SERVER 0x00000800 Xenix server
SV_TYPE_MFPN 0x00004000 Microsoft File and Print for Netware
SV_TYPE_NT 0x00001000 Windows NT (either Workstation or Server)
SV_TYPE_WFW 0x00002000 Server running Windows for Workgroups
SV_TYPE_SERVER_NT 0x00008000 Windows NT Non-DC server
SV_TYPE_POTENTIAL_BROWSER 0x00010000 Server that can run the Browser service
SV_TYPE_BACKUP_BROWSER 0x00020000 Server running a Browser service as backup
SV_TYPE_MASTER_BROWSER 0x00040000 Server running the master Browser service
SV_TYPE_DOMAIN_MASTER 0x00080000 Server running the domain master Browser
SV_TYPE_DOMAIN_ENUM 0x80000000 Primary Domain
SV_TYPE_WINDOWS 0x00400000 Windows 95 or later
SV_TYPE_ALL 0xFFFFFFFF All servers
domainA pointer to a Unicode string containing the name of the domain for which a list of servers is to returned. If NULL is specified, the primary domain is implied.resume_handleReserved. Must be set to zero. Use the Wnet functions. Return ValuesIf the function returns account information, the return value is NERR_Success.
If the function fails, the return value is one of the following error codes:Value Meaning
ERROR_ACCESS_DENIED The user does not have access to the requested information.
NERR_InvalidComputer The computer name is invalid.
ERROR_NO_BROWSER_SERVERS_FOUND No browser servers found.
ERROR_MORE_DATA More entries are available with subsequent calls.
DWORD level,
LPBYTE *bufptr,
DWORD prefmaxlen,
LPDWORD entriesread,
LPDWORD totalentries,
DWORD servertype,
LPTSTR domain,
LPDWORD resume_handle
);
ParametersservernamePointer to a Unicode string containing the name of the remote server on which the function is to execute. A NULL pointer or string specifies the local computer.levelSpecifies one of the following values to return the level of information provided.Value Meaning
100 The bufptr parameter points to an array of SERVER_INFO_100 structures.
101 The bufptr parameter points to an array of SERVER_INFO_101 structures.
bufptrPointer to the buffer in which the data set with the level parameter is stored. prefmaxlenPreferred maximum length, in 8-bit bytes of returned data.entriesreadOn return, the actual enumerated element count is located in the doubleword pointed to by entriesread.totalentriesReturns the total number of visible servers and workstations on the network. servertypeA DWORD mask that filters server entries to return from the enumeration. The defined mask bits specify:Symbolic constant Value Meaning
SV_TYPE_WORKSTATION 0x00000001 All LAN Manager workstations
SV_TYPE_SERVER 0x00000002 All LAN Manager servers
SV_TYPE_SQLSERVER 0x00000004 Any server running with Microsoft SQL Server
SV_TYPE_DOMAIN_CTRL 0x00000008 Primary domain controller
SV_TYPE_DOMAIN_BAKCTRL 0x00000010 Backup domain controller
SV_TYPE_TIMESOURCE 0x00000020 Server running the Timesource service
SV_TYPE_AFP 0x00000040 Apple File Protocol servers
SV_TYPE_NOVELL 0x00000080 Novell servers
SV_TYPE_DOMAIN_MEMBER 0x00000100 LAN Manager 2.x Domain Member
SV_TYPE_LOCAL_LIST_ONLY 0x40000000 Servers maintained by the browser. See the following Res section.
SV_TYPE_PRINT 0x00000200 Server sharing print queue
SV_TYPE_DIALIN 0x00000400 Server running dial-in service
SV_TYPE_XENIX_SERVER 0x00000800 Xenix server
SV_TYPE_MFPN 0x00004000 Microsoft File and Print for Netware
SV_TYPE_NT 0x00001000 Windows NT (either Workstation or Server)
SV_TYPE_WFW 0x00002000 Server running Windows for Workgroups
SV_TYPE_SERVER_NT 0x00008000 Windows NT Non-DC server
SV_TYPE_POTENTIAL_BROWSER 0x00010000 Server that can run the Browser service
SV_TYPE_BACKUP_BROWSER 0x00020000 Server running a Browser service as backup
SV_TYPE_MASTER_BROWSER 0x00040000 Server running the master Browser service
SV_TYPE_DOMAIN_MASTER 0x00080000 Server running the domain master Browser
SV_TYPE_DOMAIN_ENUM 0x80000000 Primary Domain
SV_TYPE_WINDOWS 0x00400000 Windows 95 or later
SV_TYPE_ALL 0xFFFFFFFF All servers
domainA pointer to a Unicode string containing the name of the domain for which a list of servers is to returned. If NULL is specified, the primary domain is implied.resume_handleReserved. Must be set to zero. Use the Wnet functions. Return ValuesIf the function returns account information, the return value is NERR_Success.
If the function fails, the return value is one of the following error codes:Value Meaning
ERROR_ACCESS_DENIED The user does not have access to the requested information.
NERR_InvalidComputer The computer name is invalid.
ERROR_NO_BROWSER_SERVERS_FOUND No browser servers found.
ERROR_MORE_DATA More entries are available with subsequent calls.
这个我也看了,我想要一个在Delphi中能运行的例子
_SERVER_INFO_101 = record
sv101_platform_id:DWORD;
sv101_name:PWideChar;
sv101_version_major:DWORD;
sv101_version_minor:DWORD;
sv101_type:DWORD;
sv101_comment:PWideChar;
end;
P_SERVER_INFO_101 = ^_SERVER_INFO_101;
_SERVER_INFO_101ARRAY = array of _SERVER_INFO_101;
.......
CONST
SV_TYPE_WORKSTATION = $00000001;
........
function NetServerEnum(
servername:PWideChar;
level:DWORD;
bufptr:PBYTE;
prefmaxlen:DWORD;
entriesread:LPDWORD;
totalentries:LPDWORD;
servertype:DWORD;
domain:PWideChar;
resume_handle:LPDWORD
):NET_API_STATUS;stdcall;
external NetApi32 name 'NetServerEnum';........
procedure TForm1.FormCreate(Sender: TObject);
var pwc:PWideChar;
e,te,eid:DWORD;
i:integer;
data:_SERVER_INFO_101ARRAY;
begin
SetLength(data,1024);
ZeroMemory(@data[0],length(data)*sizeof(data[0]));for i:=0 to length(data)-1 do
begin
GetMem(data[i].sv101_name,100);
StringToWideChar('test NAME value',data[i].sv101_name,100);
GetMem(data[i].sv101_comment,100);
StringToWideChar('test COMENT value',data[i].sv101_comment,100);
end;
eid:=NetServerEnum(nil,
101,
@data[0],
length(data)*sizeof(data[0]),
@e,
@te,
SV_TYPE_WORKSTATION,
nil,
0);if eid=0
then begin
if te>0
then begin
GetMem(pwc,100);
StringToWideChar('NEXT SERVER:',pwc,100);
for i:=0 to e-1 do
MessageBoxW(0,data[i].sv101_name,pwc,0);
ShowMessage('Count: '+IntToStr(i));
Dispose(pwc);
end;
end
else MessageBoxA(0,PChar(IntToStr(eid)),PChar('ERROR CODE:'),$10);for i:=0 to length(data)-1 do
begin
Dispose(data[i].sv101_name);
Dispose(data[i].sv101_comment);
end;SetLength(data,0);
end
unit NetApi32; // Interface for NetApi32.dll
// NB30.h - Netbios 3.0 {$DEFINE DEBUG}
{$UNDEF DEBUG} {$IFNDEF DEBUG}
{$O+,D-,Q-,R-}
{$ENDIF DEBUG} { $Revision: $ }
{ $Archive: $ }
{ $Workfile: $ }
{ $Author: $ }
{ $Date: $ }
{ $Modtime: $ }
{ $History: $ }
{ $NoKeywords: $ } interface uses
Windows; const
NCBNAMSZ = 16;
MAX_LANA = 256; type
TNCBName = Array[0..NCBNAMSZ - 1] of UCHAR; PNCB = ^TNCB;
TNCB = packed record
ncb_command : UCHAR;
ncb_retcode : UCHAR;
ncb_lsn : UCHAR;
ncb_num : UCHAR;
ncb_buffer : PUCHAR;
ncb_length : WORD;
ncb_callname : TNCBName;
ncb_name : TNCBName;
ncb_rto : UCHAR;
ncb_sto : UCHAR;
ncb_post : Pointer;
ncb_lana_num : UCHAR;
ncb_cmd_cplt : UCHAR;
ncb_reserve : array[0..9] of UCHAR;
ncb_event : THandle;
end; TNAME_BUFFER = packed record
name : TNCBName;
name_num : UCHAR;
name_flags : UCHAR;
end; TADAPTER_STATUS = packed record
adapter_address : Array[0..5] of UCHAR;
rev_major : UCHAR;
reserved0 : UCHAR;
adapter_type : UCHAR;
rev_minor : UCHAR;
duration : WORD;
frmr_recv : WORD;
frmr_xmit : WORD;
iframe_recv_err : WORD;
xmit_aborts : WORD;
xmit_success : DWORD;
recv_success : DWORD;
iframe_xmit_err : WORD;
recv_buff_unavail : WORD;
t1_timeouts : WORD;
ti_timeouts : WORD;
reserved1 : DWORD;
free_ncbs : WORD;
max_cfg_ncbs : WORD;
max_ncbs : WORD;
xmit_buf_unavail : WORD;
max_dgram_size : WORD;
pending_sess : WORD;
max_cfg_sess : WORD;
max_sess : WORD;
max_sess_pkt_size : WORD;
name_count : WORD;
end; TLANA_ENUM = packed record
length : UCHAR;
lana : Array [0..MAX_LANA - 1] of UCHAR;
end; const // Netbios commands
NCBACTION = $77; // Enables extensions to the transport interface.
// NCBACTION commands are mapped to TdiAction.
// When this code is specified, the ncb_buffer member
// points to a buffer to be filled with an ACTION_HEADER
// structure, which is optionally followed by data.
// NCBACTION commands cannot be canceled by using NCBCANCEL. NCBADDGRNAME = $36; // Adds a group name to the local name table. NCBADDNAME = $30; // Adds a unique name to the local name table.
NCBASTAT = $33; // Retrieves the status of the adapter. When this code
// is specified, the ncb_buffer member points to a buffer
// to be filled with an ADAPTER_STATUS structure,
// followed by an array of NAME_BUFFER structures. NCBCALL = $10; // Opens a session with another name. NCBCANCEL = $35; // Cancels a previous command. NCBCHAINSEND = $17; // Sends the contents of two data buffers to the
// specified session partner. NCBCHAINSENDNA = $72; // Sends the contents of two data buffers to the
// specified session partner and does not wait
// for acknowledgment. NCBDELNAME = $31; // Deletes a name from the local name table. NCBDGRECV = $21; // Receives a datagram from any name. NCBDGRECVBC = $23; // Receives broadcast datagram from any host. NCBDGSEND = $20; // Sends datagram to a specified name. NCBDGSENDBC = $22; // Sends a broadcast datagram to every host on the
// local area network (LAN). NCBENUM = $37; // Enumerates LAN adapter (LANA) numbers. When this code
// is specified, the ncb_buffer member points to a buffer
// to be filled with a LANA_ENUM structure. NCBFINDNAME = $78; // Determines the location of a name on the network.
// When this code is specified, the ncb_buffer member
// points to a buffer to be filled with a FIND_NAME_HEADER
// structure followed by one or more FIND_NAME_BUFFER structures. NCBHANGUP = $12; // Closes a specified session. NCBLANSTALERT = $73; // Notifies the user of LAN failures that last for
// more than one minute. NCBLISTEN = $11; // Enables a session to be opened with another name. NCBRECV = $15; // Receives data from the specified session partner. NCBRECVANY = $16; // Receives data from any session corresponding to a specified name. NCBRESET = $32; // Resets a LAN adapter. An adapter must be reset before
// any other NCB command that specifies the same number
// in the ncb_lana_num member will be accepted.
// The IBM NetBIOS 3.0 specification documents several
// NCB_RESET NCB's. Win32 implements the NCB.RESET using
// the dynamic link routine interface. Particular values
// can be passed in specific bytes of the NCB, more
// specifically:
// · If ncb_lsn is not 0x00, all resources associated
// with ncb_lana_num are to be freed.
// · If ncb_lsn is 0x00, all resources associated with
// ncb_lana_num are to be freed, and new resources are
// to be allocated. The ncb_callname[0] byte specifies
// the maximum number of sessions, and the
// ncb_callname[2] byte specifies the maximum number of
// names. A nonzero value for the ncb_callname[3] byte
// requests that the application use NAME_NUMBER_1. NCBSEND = $14; // Sends data to the specified session partner. NCBSENDNA = $71; // Sends data to specified session partner and does
// not wait for an acknowledgment. NCBSSTAT = $34; // Retrieves the status of the session. When this
// value is specified, the ncb_buffer member points
// to a buffer to be filled with a SESSION_HEADER
// structure, followed by one or more SESSION_BUFFER structures. NCBTRACE = $79; // Activates or deactivates NCB tracing. Support for
// this command in the system is optional and system-specific. NCBUNLINK = $70; // Unlinks the adapter. ASYNCH = $80; // high bit set == asynchronous // error codes
NRC_GOODRET = $00; // good return
// also returned when ASYNCH request accepted
NRC_BUFLEN = $01; // illegal buffer length
NRC_ILLCMD = $03; // illegal command
NRC_CMDTMO = $05; // command timed out
NRC_INCOMP = $06; // message incomplete, issue another command
NRC_BADDR = $07; // illegal buffer address
NRC_SNUMOUT = $08; // session number out of range
NRC_NORES = $09; // no resource available
NRC_SCLOSED = $0A; // session closed
NRC_CMDCAN = $0B; // command cancelled
NRC_DUPNAME = $0D; // duplicate name
NRC_NAMTFUL = $0E; // name table full
NRC_ACTSES = $0F; // no deletions, name has active sessions
NRC_LOCTFUL = $11; // local session table full
NRC_REMTFUL = $12; // remote session table full
NRC_ILLNN = $13; // illegal name number
NRC_NOCALL = $14; // no callname
NRC_NOWILD = $15; // cannot put * in NCB_NAME
NRC_INUSE = $16; // name in use on remote adapter
NRC_NAMERR = $17; // name deleted
NRC_SABORT = $18; // session ended abnormally
NRC_NAMCONF = $19; // name conflict detected
NRC_IFBUSY = $21; // interface busy, IRET before retrying
NRC_TOOMANY = $22; // too many commands outstanding, retry later
NRC_BRIDGE = $23; // ncb_lana_num field invalid
NRC_CANOCCR = $24; // command completed while cancel occurring
NRC_CANCEL = $26; // command not valid to cancel
NRC_DUPENV = $30; // name defined by anther local process
NRC_ENVNOTDEF = $34; // environment undefined. RESET required
NRC_OSRESNOTAV = $35; // required OS resources exhausted
NRC_MAXAPPS = $36; // max number of applications exceeded
NRC_NOSAPS = $37; // no saps available for netbios
NRC_NORESOURCES = $38; // requested resources are not available
NRC_INVADDRESS = $39; // invalid ncb address or length > segment
// This return code is not part of the IBM
// NetBIOS 3.0 specification and is not
// returned in the NCB structure. Instead, it
// is returned by the Netbios function.
NRC_INVDDID = $3B; // invalid NCB DDID
NRC_LOCKFAIL = $3C; // lock of user area failed
NRC_OPENERR = $3F; // NETBIOS not loaded
NRC_SYSTEM = $40; // system error
function ErrorToStr(Error : Integer) : String; implementation uses
Dialogs; function ErrorToStr(Error : Integer) : String;
begin
case Error of
NRC_GOODRET : Result := 'NRC_GOODRET';
NRC_BUFLEN : Result := 'NRC_BUFLEN';
NRC_ILLCMD : Result := 'NRC_ILLCMD';
NRC_CMDTMO : Result := 'NRC_CMDTMO';
NRC_INCOMP : Result := 'NRC_INCOMP';
NRC_BADDR : Result := 'NRC_BADDR';
NRC_SNUMOUT : Result := 'NRC_SNUMOUT';
NRC_NORES : Result := 'NRC_NORES';
NRC_SCLOSED : Result := 'NRC_SCLOSED';
NRC_CMDCAN : Result := 'NRC_CMDCAN';
NRC_DUPNAME : Result := 'NRC_DUPNAME';
NRC_NAMTFUL : Result := 'NRC_NAMTFUL';
NRC_ACTSES : Result := 'NRC_ACTSES';
NRC_LOCTFUL : Result := 'NRC_LOCTFUL';
NRC_REMTFUL : Result := 'NRC_REMTFUL';
NRC_ILLNN : Result := 'NRC_ILLNN';
NRC_NOCALL : Result := 'NRC_NOCALL';
NRC_NOWILD : Result := 'NRC_NOWILD';
NRC_INUSE : Result := 'NRC_INUSE';
NRC_NAMERR : Result := 'NRC_NAMERR';
NRC_SABORT : Result := 'NRC_SABORT';
NRC_NAMCONF : Result := 'NRC_NAMCONF';
NRC_IFBUSY : Result := 'NRC_IFBUSY';
NRC_TOOMANY : Result := 'NRC_TOOMANY';
NRC_BRIDGE : Result := 'NRC_BRIDGE';
NRC_CANOCCR : Result := 'NRC_CANOCCR';
NRC_CANCEL : Result := 'NRC_CANCEL';
NRC_DUPENV : Result := 'NRC_DUPENV';
NRC_ENVNOTDEF : Result := 'NRC_ENVNOTDEF';
NRC_OSRESNOTAV : Result := 'NRC_OSRESNOTAV';
NRC_MAXAPPS : Result := 'NRC_MAXAPPS';
NRC_NOSAPS : Result := 'NRC_NOSAPS';
NRC_NORESOURCES : Result := 'NRC_NORESOURCES';
NRC_INVADDRESS : Result := 'NRC_INVADDRESS';
NRC_INVDDID : Result := 'NRC_INVDDID';
NRC_LOCKFAIL : Result := 'NRC_LOCKFAIL';
NRC_OPENERR : Result := 'NRC_OPENERR';
NRC_SYSTEM : Result := 'NRC_SYSTEM';
NRC_PENDING : Result := 'NRC_PENDING';
end;
end; procedure ShowNetApiError(Error : Integer);
var
msg : String;
begin
msg := '';
case Error of
NRC_GOODRET : msg := 'The operation succeeded.';
NRC_BUFLEN : msg := 'An illegal buffer length was supplied.';
NRC_ILLCMD : msg := 'An illegal command was supplied.';
NRC_CMDTMO : msg := 'The command timed out';
NRC_INCOMP : msg := 'The message was incomplete. The application is to issue another command.';
NRC_BADDR : msg := 'The buffer address was illegal.';
NRC_SNUMOUT : msg := 'The session number was out of range.';
NRC_NORES : msg := 'No resource was available.';
NRC_SCLOSED : msg := 'The session was closed.';
NRC_CMDCAN : msg := 'The command was canceled.';
NRC_DUPNAME : msg := 'A duplicate name existed in the local name table.';
NRC_NAMTFUL : msg := 'The name table was full.';
NRC_ACTSES : msg := 'The command finished; the name has active sessions and is no longer registered.';
NRC_LOCTFUL : msg := 'The local session table was full.';
NRC_REMTFUL : msg := 'The remote session table was full. The request to open a session was rejected.';
NRC_ILLNN : msg := 'An illegal name number was specified.';
NRC_NOCALL : msg := 'The system did not find the name that was called.';
NRC_NOWILD : msg := 'Wildcards are not permitted in the ncb_name member.';
NRC_INUSE : msg := 'The name was already in use on the remote adapter.';
NRC_NAMERR : msg := 'The name was deleted.';
NRC_SABORT : msg := 'The session ended abnormally.';
NRC_NAMCONF : msg := 'A name conflict was detected.';
NRC_IFBUSY : msg := 'The interface was busy.';
NRC_TOOMANY : msg := 'Too many commands were outstanding; the application can retry the command later.';
NRC_BRIDGE : msg := 'The ncb_lana_num member did not specify a valid network number.';
NRC_CANOCCR : msg := 'The command finished while a cancel operation was occurring.';
NRC_CANCEL : msg := 'The NCBCANCEL command was not valid; the command was not canceled.';
NRC_DUPENV : msg := 'The name was defined by another local process.';
NRC_ENVNOTDEF : msg := 'The environment was not defined. A reset command must be issued.';
NRC_OSRESNOTAV : msg := 'Operating system resources were exhausted. The application can retry the command later.';
NRC_MAXAPPS : msg := 'The maximum number of applications was exceeded.';
NRC_NOSAPS : msg := 'No service access points (SAPs) were available for NetBIOS.';
NRC_NORESOURCES : msg := 'The requested resources were not available.';
NRC_INVADDRESS : msg := 'The NCB address was not valid.';
NRC_INVDDID : msg := 'The NCB DDID was invalid.';
NRC_LOCKFAIL : msg := 'The attempt to lock the user area failed.';
NRC_OPENERR : msg := 'An error occurred during an open operation being performed by the device driver. This return
code is not part of the IBM NetBIOS 3.0 specification.';
NRC_SYSTEM : msg := 'A system error occurred.';
NRC_PENDING : msg := 'An asynchronous operation is not yet finished.';
end; if msg <> '' then begin
ShowMessage(msg);
end;
end; function NetBios; external 'NetApi32.dll' name 'Netbios';
end.
USES COMOBJprocedure TForm1.Button1Click(Sender: TObject);
var
SQLServer:Variant;
ServerList:Variant;
i,nServers:integer;
sRetValue:String;
begin
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList:= SQLServer.ListAvailableSQLServers;
nServers:=ServerList.Count;
for i := 1 to nservers do
ListBox1.Items.Add(ServerList.Item(i));
SQLServer:=NULL;
serverList:=NULL;
end;查找到的服务器名都存在 serverlist.item里面了,你只要把他取出再付给
adoconnectionstring中的date sourcE就行了