----Windows 下,使Windows 数(WNet
 
现,WNet 的。
----Wnet
有:WnetAddConnection , WnetAddConnection2 , WnetAddConnection3 ,
WnetCancelConnection2
等。 WnetAddConnection2WnetCancelConnection2 数。

----WNetAddConnection2
Windows.pas 下:

----function WNetAddConnection2(var lpNetResource: TNetResource;lpPassword, lpUserName:

----PChar; dwFlags: DWORD): DWORD; stdcall;

----
数,lpNetResouce 构,为:

typedef  struct _NETRESOUCE{
    DWORD dwScope;  
    DWORD dwType;  
    DWORD dwDisplayType;
    DWORD dwUsage;
    LPTSTR lpLocalName;
    LPTSR  lpRemoteName;
    LPTSr  lpProvider;
} NETRESOURCE;

----
使dwType,lpLocalName,lpRemoteName,lpProvider 数。下:

----dwType :
型,RESOURCETYPE_ANY( ),
RESOURCETYPE_DISK(
) , RESOURCETYPE_PRINT源)。

----lpLocalName :
备。

----lpRemoteName :
名。

----lpProvider :
商。空,知。

----WNetAddConnection2
lpPassword 令。

----lpUserName
名。dwFlags
接(0 接,CCONNECT_UPDATE_PROFILE 接)。

----WnetCancelConnection2
Windows .pas 下:

----function WNetCancelConnection2(lpName: PChar;
  dwFlags: DWORD; fForce: BOOL):DWORD; stdcall;

----lpName :
器。

----dwFlags :
上。

----fForce : True
开,器;
False
败。



----
Delphi File New ApplicationForm1 Button
Button1 Click 码:
procedure TForm1.Button1Click(Sender : TObject);
var
  NetSource : TNetResource;
begin
  with NetSource do
  begin
    dwType := RESOURCETYPE_ANY;
    lpLocalName := ‘X:';
    //

    lpRemoteName := ‘//hqServer/sys';
    //

    lpProvider := ‘';  
    //
,
     
使lpRemoteName 值。
  end;
  WnetAddConnection2(NetSource,‘Password',‘Guest',
   //
GuestPassword
  CONNECT_UPDATE_PROFILE);
   //

  //
Windows
   
X
  if MessageDlg(‘Are you sure to disconnect Drive ?',
 
  mtConfirmation, [mbYes, mbNo], 0) = mrYes
  then      
    //
开,
     
X
 WNetCancelConnection2( ‘X:', CONNECT_UPDATE_
PROFILE, True);  
end;
end;
============================================================================================

 
 
 
 
localname:本地磁盘号 如:Y: Z:
remotename: 共享路径 如 ://server/share
username : 用户名
password: 密码
function connectserver(localname: string; remotename: string; username: string; password: string): boolean;
var
 NetSource: TNetResource; Errinfo: longint;
begin
 with NetSource do begin
    dwType := RESOURCETYPE_ANY; //RESOURCETYPE_DISK
    lpLocalName := pchar(localname);
         // 将远程资源映射到此驱动器
    lpRemoteName := pchar(remotename);
        // 远程网络资 源
    lpProvider := '';
        // 必须赋值,如为空则使用lpRemoteName 的值。
 end;
 ErrInfo := WnetAddConnection2(NetSource, pchar(password), pchar(username), 0);
 result := (ErrInfo = NO_ERROR);
end;
posted on 2013-05-12 17:01  Values  阅读(334)  评论(0编辑  收藏  举报