Home > Database > Mysql Tutorial > Delphi访问共享

Delphi访问共享

WBOY
Release: 2016-06-07 15:02:01
Original
1196 people have browsed it

var NetSource: TNetResource; Error: LongInt; a: Cardinal; begin with NetSource do begin dwType := RESOURCETYPE_ANY; lpLocalName := 'Z:'; lpRemoteName := '\\192.168.2.4\arc'; lpProvider := ''; end; // case WNetAddConnection3(Handle, NetSour

var

  NetSource: TNetResource;

  Error: LongInt;

  a: Cardinal;

begin

  with NetSource do

  begin

    dwType  := RESOURCETYPE_ANY;

    lpLocalName := 'Z:';

    lpRemoteName := '\\192.168.2.4\arc';

    lpProvider := '';

  end;

//  case  WNetAddConnection3(Handle, NetSource, '','', CONNECT_UPDATE_PROFILE) of

//WNetAddConnection3 带有密码输入框  WNetAddConnection2 没有

 case WNetAddConnection3(Handle, NetSource, '', '', CONNECT_UPDATE_PROFILE or CONNECT_INTERACTIVE) of

   NO_ERROR: ShowMessage('成功') ;

   ERROR_ACCESS_DENIED: showmessage('访问被拒绝');

   ERROR_ALREADY_ASSIGNED:ShowMessage('设备参数中指定的lpLocalName已经连接。');

   ERROR_BAD_DEV_TYPE:ShowMessage('设备类型和资源类型不匹配。');

   ERROR_BAD_DEVICE:ShowMessage('在lpLocalName指定的值是无效的');

   ERROR_BAD_NET_NAME: ShowMessage('中指定的值lpRemoteName参数无效或无法找到。');

   ERROR_BAD_PROFILE :ShowMessage('用户配置文件的格式不正确')   ;

   ERROR_CANNOT_OPEN_PROFILE :ShowMessage('统无法打开用户配置文件来处理持久连接。');

   ERROR_DEVICE_ALREADY_REMEMBERED: ShowMessage('一个条目中指定的设备lpLocalName已经在用户概要。') ;

   ERROR_EXTENDED_ERROR:ShowMessage('一个特定于网络错误发生。为了描述的错误,使用WNetGetLastError函数。');

   ERROR_INVALID_PASSWORD:ShowMessage('指定的密码是无效的。');

   ERROR_NO_NET_OR_BAD_PATH:ShowMessage('操作无法进行,因为不是一个网络组件没有启动或指定的名称不能用。');

   ERROR_NO_NETWORK:ShowMessage('网络不存在.');

   ERROR_SESSION_CREDENTIAL_CONFLICT: //这里为第二次输入冲突 但是共享文件夹已经可以访问无需密码了,所以这里 不提示

 else

   ShowMessage('其他意外終止!');

 

 end;

以上,也可以用客户端和服务端 之间通讯传输文件,就不用考虑这么多了



映射网络资源到本地驱动器 网上摘抄

function MapNetworkDrive(const handle : THandle; const uncPath : string) : string;

 //returns mapped drive ("z:") on success 

 //or uncPath on failure / cancel

 var

   cds : TConnectDlgStruct;

   netResource : TNetResource;

 begin

   result := uncPath;

 

   ZeroMemory(@netResource, SizeOf(TNetResource)) ;

   netResource.dwType := RESOURCETYPE_DISK;

   netResource.lpRemoteName := PChar(uncPath) ;

 

   cds.cbStructure := SizeOf(TConnectDlgStruct) ;

   cds.hwndOwner := handle;

   cds.lpConnRes := @netResource;

   cds.dwFlags := CONNDLG_PERSIST;

 

   if WNetConnectionDialog1(cds) = NO_ERROR then

   begin

     result := Chr(-1 + Ord('A') + cds.dwDevNum) + DriveDelim;

   end;

 end;

使用:
MapNetworkDrive(Handle, '')

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template