各位大神,最近需要拷貝檔案到局域網某共享檔案夾,該共享檔案夾設定了訪問權限。于是,我找到了下面類似的代碼:
var
netsorce: TNetResource;
mResult: cardinal;
begin
Result:=False;
with netsorce do
begin
dwType := RESOURCETYPE_DISK;
dwDisplayType:=RESOURCEDISPLAYTYPE_SHARE;
lpLocalName := 'v:';
lpRemoteName := PAnsiChar('\\10.11.1.2\file1\');
lpProvider := '';
end;
case WNetAddConnection2(netsorce, @pwd,@user, CONNECT_UPDATE_PROFILE) of
NO_ERROR: begin Result:=True; end;
ERROR_ACCESS_DENIED: showmessage('Access is denied.');
ERROR_ALREADY_ASSIGNED: ShowMessage('The device specified in the lpLocalName parameter is already connected.');
ERROR_BAD_DEV_TYPE: ShowMessage('The device type and the resource type do not match.');
ERROR_BAD_DEVICE: ShowMessage('The value specified in lpLocalName is invalid');
ERROR_BAD_NET_NAME: ShowMessage('The value specified in the lpRemoteName parameter is not valid or cannot be located.');
ERROR_BAD_PROFILE: ShowMessage(' The user profile is in an incorrect format.');
ERROR_CANNOT_OPEN_PROFILE: ShowMessage(' The system is unable to open the user profile to process persistent connections. ');
ERROR_DEVICE_ALREADY_REMEMBERED: ShowMessage('An entry for the device specified in lpLocalName is already in the user profile.');
ERROR_EXTENDED_ERROR: ShowMessage('A network-specific error occurred. To get a description of the error, use the WNetGetLastError function. ');
ERROR_INVALID_PASSWORD: ShowMessage(' The specified password is invalid. ');
ERROR_NO_NET_OR_BAD_PATH: ShowMessage(' The operation cannot be performed because either a network component is not started or the specified name cannot be used.');
ERROR_NO_NETWORK: ShowMessage(' The network is not present. ');
else
begin
ShowMessage(' 其他錯誤. ');
end;
但是問題是,老連接不上啊,老提示ERROR_NO_NET_OR_BAD_PATH,那個地址應該是沒錯的,還是說在這個函式里面,這個地址的填寫格式不該這樣?那該哪樣啊?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/143632.html
標籤:語言基礎/算法/系統設計
