const
NETBUFF_SIZE = $208;
type
NetSessionEnum = function(ServerName: LPSTR; Level: DWORD; Bufptr: PBYTE; MaxLen: DWORD; total: LPDWORD; resume_hwnd: LPDWORD): Dword; stdcall;
NetSessionDel = function(ServerName: LPSTR; ClientName: LPSTR; UserName: LPSTR): dword; stdcall;
function NetCloseAll: Boolean;
type
TbyBuff=array[0..NETBUFF_SIZE-1] of byte;
var
byBuff:TBybuff;
dwNetRet,i,dwEntries,dwTotalEntries:dword;
szClient:LPSTR;
dwUserName:LPSTR;
bRet:boolean;
lpbyBuff:^TbyBuff;
h:hwnd;
EnumProc:NetSessionEnum;
DelProc:NetSessionDel;
begin
h:=LoadLibrary('svrapi.dll');
lpbybuff:=@bybuff;
bRet:=false;
if h<>0 then
begin
EnumProc:=GetProcAddress(h,'NetSessionEnum');
DelProc:=GetprocAddress(h,'NetSessionDel');
if Assigned(EnumProc) and Assigned(DelProc) then
begin
dwNetRet:=EnumProc(nil,$32,@byBuff,NETBUFF_SIZE,@dwEntries,@dwTotalEntries);
if dwNetRet=0 then
begin
bRet:=true;
for i:=0 to dwTotalEntries-1 do
begin
szClient:=LPSTR(lpbybuff^[0]);
dwUserName:=LPSTR(LPbybuff^[2]);
dwNetRet:=DelProc(nil,szClient,dwUserName);
if dwNetRet<>0 then
begin
bRet:=false;
break;
end;
lpbybuff:=pointer(integer(lpbybuff)+26);
end;
end; //NetSessionEnum
end
else
bRet:=false;
end //GetProcAddress
else
bRet:=false;
FreeLibrary(h);
result:=bRet;
end;