提示:' ERROR_NO_NET_OR_BAD_PATH'
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.代碼如如下..>>>>>>>>>>>>>>>>
spath:='\\192.170.111.9\';
UName:=PChar('administrator');
pwd:=PChar('longlongago');
with netsorce do
begin
dwType:=RESOURCETYPE_DISK;
lpLocalName:='v:';
lpRemoteName:=PAnsiChar(spath);
lpProvider:='';
end;
case WNetAddConnection2(netsorce,@UName,@pwd,CONNECT_UPDATE_PROFILE) of NO_ERROR: ShowMessage('成功') ;
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
ShowMessage('其他意外終止!'); end;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.代碼如如下..>>>>>>>>>>>>>>>>
spath:='\\192.170.111.9\';
UName:=PChar('administrator');
pwd:=PChar('longlongago');
with netsorce do
begin
dwType:=RESOURCETYPE_DISK;
lpLocalName:='v:';
lpRemoteName:=PAnsiChar(spath);
lpProvider:='';
end;
case WNetAddConnection2(netsorce,@UName,@pwd,CONNECT_UPDATE_PROFILE) of NO_ERROR: ShowMessage('成功') ;
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
ShowMessage('其他意外終止!'); end;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
\\192.170.111.9\d$
回车后,会弹出登录框,输入用户名有密码可以成功显示对方目录的话,按下面改:spath:='\\192.170.111.9\';
改为
spath:='\\192.170.111.9\d$';
再试下你要给个路径的,至少也要有对方的盘符 c$ d$ c$\temp d$\test这样的