Kod: Kodu kopyalamak için üzerine çift tıklayın!
unction NetServerEnum(const ServerName:PWideString;level:DWORD;var Buffer:Pointer;
PrefMaxLen:DWORD;var EntriesRead:DWORD;var TotalEntries:DWORD;ServerType:DWORD;
const Domain:PWideChar;var ResumeHandle:DWORD):DWORD;stdcall;external'netapi32.dll';
function NetApiBufferFree(Buffer:Pointer):DWORD;stdcall;external 'netapi32.dll';
function GetSQLServerNames:TStrings;
type
TServerInfo101=record
platform_id:DWORD;
name:PWideChar;
version_major,version_minor,server_type:DWORD;
comment:PWideChar;
end;
PServerInfo101=^TServerInfo101;
var Buffer:Pointer;
EntriesRead,i,ErrCode,ResumeHandle,TotalEntries:DWORD;
PDomainUnicode:PWideChar;
ServerInfo:PServerInfo101;
begin
Result:=TStringList.Create;
ResumeHandle:=0;
PDomainUnicode:=nil;
errCode:=NetServerEnum(nil,101,Buffer,DWORD(-1),EntriesRead,TotalEntries,4,PDomainUnicode,ResumeHandle);
if(errCode<>0)then raise EWin32Error.Create('Can''t enumerate servers');
try
ServerInfo:=Buffer;
for i:=1to EntriesRead do
begin
Result.Add(ServerInfo^.name);
Inc(ServerInfo);
end;
finally
NetApiBufferFree(Buffer);
end;
end;
procedure TForm1.Button1Click(Sender:TObject);
begin
ComboBox1.Items:=GetSQLServerNames;
end;