如何访问局域网上的文件

类别:Delphi 点击:0 评论:0 推荐:

var
  NetSource : TNetResource;    file://连接服务器结构
  dwResult:DWORD;               file://连接文件服务器的返回值

procedure ConnectServer;
begin
    g_bFlag:=True;
    NetSource.dwType:= RESOURCETYPE_ANY;
    NetSource.lpLocalName:='';
    NetSource.lpRemoteName:=PAnsiChar('\\'+g_sServerIp);
    NetSource.lpProvider:='';
    dwResult:=WnetAddConnection2(NetSource,PAnsiChar(g_sServerPassWord),PAnsiChar(g_sServerUserName),CONNECT_UPDATE_PROFILE);
    if dwResult<>0 then
    begin
        MessageDlg('连接文件服务器失败!'#13#10'请重新设置!',mtWarning,[mbOk],0);
        g_bFlag:=False;
    end;
end;

procedure DisconnectServer;
begin
    if g_bFlag then
        WNetCancelConnection2(PAnsiChar('\\'+g_sServerIp), CONNECT_UPDATE_PROFILE, True);
end;

本文地址:http://com.8s8s.com/it/it5428.htm