製作類似 WebDrive / NetDrive 功能 |
尚未結案
|
blue
中階會員 發表:170 回覆:136 積分:81 註冊:2002-04-15 發送簡訊給我 |
|
wangccw
一般會員 發表:21 回覆:39 積分:17 註冊:2005-01-30 發送簡訊給我 |
[code delphi] unit NetMapDrive; interface uses Windows,dialogs,SysUtils,Messages,waitUnit1; type TNetMapDrive = class(TObject) private NRW: TNetResource; FWaitForm: TWaitForm; public MsgMode:Boolean; function CancelMapDrive(Drive:String):Boolean; function ConnectionMapDrive(Drive,Server,RemoteName:String):Boolean;overload; function ConnectionMapDrive(Drive,Server,RemoteName,User,Passwd:String):Boolean;overload; constructor Create; destructor Destroy; override; end; implementation constructor TNetMapDrive.Create; begin inherited; MsgMode:=false; FWaitForm:=TWaitForm.Create(nil); end; destructor TNetMapDrive.Destroy; begin inherited; FWaitForm.Free; end; function TNetMapDrive.CancelMapDrive(Drive:String):Boolean; var RetValue:DWORD; ErrMsg:String; begin RetValue:=NO_ERROR; if(GetDriveType(PChar(Drive)) > DRIVE_NO_ROOT_DIR) then RetValue:=WNetCancelConnection2(PChar(Drive),CONNECT_UPDATE_PROFILE,TRUE); if(RetValue = NO_ERROR) then Result:=true else begin case RetValue of ERROR_BAD_PROFILE: ErrMsg:='使用者相關資訊錯誤!!'; //'The user profile is in an incorrect format'; ERROR_CANNOT_OPEN_PROFILE: ErrMsg:='系統無法開啟使用者相關資訊去執行此作業!!'; //'The system is unable to open the user profile to process persistent connections'; ERROR_DEVICE_IN_USE: ErrMsg:='裝置正在使用中,無法取消連線!!';//'The device is in use by an active process and cannot be disconnected'; ERROR_EXTENDED_ERROR: ErrMSg:='發生網路特定的錯誤!!'; //'A network-specific error occurred'; ERROR_NOT_CONNECTED: ErrMsg:='無連線的網路資源!!'; //'The name specified by the lpName parameter is not a redirected device, or the system is not currently connected to the device specified by the parameter'; ERROR_OPEN_FILES: ErrMsg:='檔案正在使用中,無法取消連線'; //'There are open files'; end; if(MsgMode) then ShowMessage(ErrMsg); Result:=false; end; end; function TNetMapDrive.ConnectionMapDrive(Drive,Server,RemoteName:String):Boolean; var RetValue:Boolean; begin RetValue:=ConnectionMapDrive(Drive,Server,RemoteName,'',''); Result:=RetValue; end; function TNetMapDrive.ConnectionMapDrive(Drive,Server,RemoteName,User,Passwd:String):Boolean; var RetValue:DWORD; RemotePath,ErrMsg:String; begin RetValue:=NO_ERROR; FwaitForm.Show; FWaitForm.Update; if CancelMapDrive(Drive) then begin with NRW do begin dwType := RESOURCETYPE_DISK; lpLocalName := PChar(Drive); RemotePath:='\\' Server '\' RemoteName; lpRemoteName := PChar(RemotePath); lpProvider := ''; end; RetValue:=WNetAddConnection2(NRW, PCHAR(Passwd), PCHAR(User),CONNECT_UPDATE_PROFILE); if(RetValue <> NO_ERROR) then begin case RetValue of ERROR_ACCESS_DENIED: ErrMsg:='網路資源拒絕存取!!'; //'Access to the network resource was denied'; ERROR_ALREADY_ASSIGNED: ErrMsg:='磁碟機名稱已連線其它網路資源!!';//'The local device is already connected to a network resource'; ERROR_BAD_DEV_TYPE: ErrMsg:='本機端裝置與網路資源無法符合!!'; //The type of local device and the type of network resource do not match'; ERROR_BAD_DEVICE: ErrMsg:='指定的磁碟名稱錯誤!!'; //'The value specified by lpLocalName is invalid'; ERROR_BAD_NET_NAME: ErrMsg:='網路資源無法取得或名稱錯誤!!'; //'The resource name is invalid,or thye named resource cannot be located'; ERROR_BAD_PROFILE: ErrMsg:='使用者相關資訊錯誤!!'; // 'The user profile is in an incorrect format'; ERROR_BAD_PROVIDER: ErrMsg:='資源提供者無法符合網路上任一提供者!!'; //'The value specified by lpProvider does not match any provider'; ERROR_BUSY: ErrMsg:='資源提供者忙碌中,請重試!!'; //'The router or provider is busy, possibly initializing. The caller should retry'; ERROR_CANCELLED: ErrMsg:='網路連結已被取消!!'; //'The attempt to make the connection was cancelled by the user through a dialog box from one of the network resource providers, or by a called resource'; ERROR_DEVICE_ALREADY_REMEMBERED: ErrMsg:='指定的磁碟名稱已經存在!!'; //'An entry for the device specified in lpLocalName is already in the user profile'; ERROR_EXTENDED_ERROR: ErrMsg:='發生網路特定的錯誤!!'; //'A network-specific error occured'; ERROR_INVALID_PASSWORD: ErrMsg:='密碼錯誤!!'; //'The specified password is invalid'; ERROR_NO_NET_OR_BAD_PATH: ErrMsg:='網路的元件無法起始,或指定的路徑無法取得!!'; //'A network component has not started, or the specified name could not be handled'; ERROR_NO_NETWORK: ErrMsg:='沒有網路連結!!'; //'There is no network present'; end; // end of case if(MsgMode) then ShowMessage(ErrMsg); end;// end of if end; // end of if SendMessage(FWaitForm.Handle,WM_CLOSE,0,0); if RetValue = NO_ERROR then Result:=true else Result:=false; end; end. [/code] 請自行參考之 |
blue
中階會員 發表:170 回覆:136 積分:81 註冊:2002-04-15 發送簡訊給我 |
|
wangccw
一般會員 發表:21 回覆:39 積分:17 註冊:2005-01-30 發送簡訊給我 |
|
blue
中階會員 發表:170 回覆:136 積分:81 註冊:2002-04-15 發送簡訊給我 |
===================引 用 wangccw 文 章=================== 這個議題好大~~ 建議用現成的 novell netdirve或 其它家的 netdriver來用就好了 = =" 關於 webdav 的部份, ip*works! 有操作 webdav 的元件,不過離你要的 netdrive 有很大的距離。 大家如果有 net drive 實作的方向,希望能夠提出來討論。 Hi,您好: 感謝先進的指導, 因公司要做產品, 使用 novell netdrive 怕會牽涉到版權問題, 有另一套名稱也叫 NetDrive, 看了一下,原本是 Open source 的 Project, 但,最終成了商業化的產品, Source也未開放出來, 雖說Home user是免費使用, 但,若將之包入產品中,恐還是會有上面的問題, 謝謝! |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |