我用API函数NetServerEnum,如果只给域名则返回错误6118,如果服务器域名都给则返回错误2351<br>我的代码如下:<br>//获得指定域中可见的指定类型的所有服务器<br>Function NetServerEnum(ServerName:LPTSTR;Level
WORD;BufPtr:SERVER_INFO_101_Array;PrefMaxLen
WORD;EntriesRead:LPDWORD;Totalentries:LPDWORD;ServerType
WORD;Domain:LPTSTR;Resume_handle:LPDWORD):integer; stdcall; external 'netapi32.dll';<br>//获得域控制器<br>Function GetDomain_Ctrl_ComputerName(Domain:string):string;<br>var<br> V_ServerName:LPTSTR;<br> V_Level
WORD;<br> V_BufPtr:SERVER_INFO_101_Array;<br> V_PrefMaxLen
WORD;<br> V_EntriesRead:LPDWORD;<br> V_Totalentries:LPDWORD;<br> V_ServerType
WORD;<br> V_Domain:LPTSTR;<br> V_Resume_handle:LPDWORD;<br> TempResult
WORD;<br>begin<br> V_ServerName:='ybl';<br> V_Level:=101;<br> SetLength(V_BufPtr,20);<br> V_PrefMaxLen :=1024;<br> new(V_EntriesRead);<br> V_EntriesRead^:=1;<br> new(V_Totalentries);<br> V_Totalentries^:=1;<br> V_ServerType :=$00000008;<br> V_Domain :=Pchar(Domain);<br> new(V_Resume_handle);<br> V_Resume_handle^ :=0;<br> TempResult:=NetServerEnum(V_ServerName,V_Level,V_BufPtr,V_PrefMaxLen,V_EntriesRead,V_Totalentries,V_ServerType,V_Domain,V_Resume_handle);<br> if TempResult=NO_ERROR then<br> begin<br> TempResult:=NetServerEnum(V_ServerName,V_Level,V_BufPtr,V_PrefMaxLen,V_EntriesRead,V_Totalentries,V_ServerType,V_Domain,V_Resume_handle);<br> GetDomain_Ctrl_ComputerName :=V_BufPtr[0].sv101_name;<br> //Application.MessageBox(pchar(inttostr(TempResult)),'dsa',mb_ok);<br> end<br>end;<br><br>