怎样断开网络 ( 积分: 100 )

  • 主题发起人 主题发起人 minzhongshan
  • 开始时间 开始时间
M

minzhongshan

Unregistered / Unconfirmed
GUEST, unregistred user!
请问大家怎样断开网络,即用程序控制网络
 
请问大家怎样断开网络,即用程序控制网络
 
//断开网络连接
function NetCloseAll:boolean;
const
NETBUFF_SIZE=$208;
type
NET_API_STATUS=DWORD;
LPByte=PByte;
var
dwNetRet :DWORD;
i :integer;
dwEntries :DWORD;
dwTotalEntries :DWORD;
szClient :LPWSTR;
dwUserName :DWORD;
Buff :array[0..NETBUFF_SIZE-1]of byte;
Adword :array[0..NETBUFF_SIZE div 4-1] of dword;
NetSessionEnum:function ( ServerName:LPSTR;
Reserved:DWORD;
Buf:LPByte;
BufLen:DWORD;
ConnectionCount:LPDWORD;
ConnectionToltalCount:LPDWORD ):NET_API_STATUS;
stdcall;

NetSessionDel:function ( ServerName:LPWSTR;
UncClientName: LPWSTR ;
UserName: dword):NET_API_STATUS;
stdcall;
LibHandle : THandle;
begin
Result:=false;
try
{ 加载 DLL }
LibHandle := LoadLibrary('svrapi.dll');
try
{ 如果加载失败,LibHandle = 0.}
if LibHandle = 0 then
raise Exception.Create('不能加载SVRAPI.DLL');
{ DLL 加载成功,取得到 DLL 输出函数的连接然後调用 }
@NetSessionEnum := GetProcAddress(LibHandle, 'NetSessionEnum');
@NetSessionDel := GetProcAddress(LibHandle, 'NetSessionDel');

if (@NetSessionEnum = nil)or(@NetSessionDel=nil) then
RaiseLastWin32Error { 连接函数失败 }
else
begin
dwNetRet := NetSessionEnum( nil,$32, @Buff,
NETBUFF_SIZE, @dwEntries,
@dwTotalEntries );
if dwNetRet = 0 then
begin
Result := true;
for i:=0 to dwTotalEntries-1 do
begin
Move(Buff,Adword,NETBUFF_SIZE);
szClient:=LPWSTR(Adword[0]);
dwUserName := Adword[2];
dwNetRet := NetSessionDel( nil,szClient,dwUserName);
if( dwNetRet <> 0 ) then
begin
Result := false;
break;
end;
Move(Buff[26],Buff[0],NETBUFF_SIZE-(i+1)*26);
end
end
else
Result := false;
end;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
except
end;
end;
 
多谢你!我试一下先
 
后退
顶部