CB中如何实现网络驱动器的映射?

CM1979 2002-02-27 01:13:19
在C++Builder中,如何用代码实现网络驱动器的映射?指定映射某台机器上的共享目录,并且该目录设置了访问密码和用户名。
请高手赐教!
...全文
60 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
CM1979 2002-02-27
  • 打赏
  • 举报
回复
非常感谢:)
CM1979 2002-02-27
  • 打赏
  • 举报
回复
非常感谢:)
Wingsun 2002-02-27
  • 打赏
  • 举报
回复
如下几个函数可供使用:
DWORD WNetAddConnection(
LPTSTR lpRemoteName, // pointer to network device name
LPTSTR lpPassword, // pointer to password
LPTSTR lpLocalName // pointer to local device name
);

DWORD WNetAddConnection2(
LPNETRESOURCE lpNetResource, // points to structure that
// specifies connection details
LPCTSTR lpPassword, // points to password string
LPCTSTR lpUsername, // points to user name string
DWORD dwFlags // set of bit flags that specify
// connection options
);

DWORD WNetAddConnection3(
HWND hwndOwner, // handle to an owner window for
// network provider dialog boxes
LPNETRESOURCE lpNetResource, // pointer to structure that
// specifies connection details
LPTSTR lpPassword, // pointer to password string
LPTSTR lpUserName, // pointer to user name string
DWORD dwFlags // set of bit flags that specify
// connection options
);
前面的兄弟已经说得很明白了,补充一点。
caoguangxin 2002-02-27
  • 打赏
  • 举报
回复
你试试看下面的代码:
void __fastcall TForm1::btnNetDriveMapClick(TObject *Sender)
{
NETRESOURCE NR;
DWORD dwResult;
AnsiString Msg ;

char Remote[128], Local[128];
char Login[32], Password[32] ;

wsprintf((LPSTR) Remote , "%s", txtRemoteName->Text);
wsprintf((LPSTR) Local , "%s", txtLocalName->Text);
wsprintf((LPSTR) Login , "%s", txtLogin->Text);
wsprintf((LPSTR) Password, "%s", txtPassword->Text);

NR.dwScope = RESOURCE_GLOBALNET ;
NR.dwType = RESOURCETYPE_ANY ;
NR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE ;
NR.dwUsage = RESOURCEUSAGE_CONNECTABLE ;
NR.lpRemoteName = Remote ;
NR.lpLocalName = Local;
NR.lpProvider = NULL ;

// 连接网络驱动器
dwResult = WNetAddConnection2(&NR,
Password,
Login,
false) ;

switch (dwResult)
{
case ERROR_ACCESS_DENIED:
Msg = "Access to the network resource was denied." ;
break ;
case ERROR_ALREADY_ASSIGNED:
Msg = "The local device is already connecteded to a network resource." ;
break ;
case ERROR_BAD_DEV_TYPE:
Msg = "The type of local device and the type of network resource do not match." ;
break ;
case ERROR_BAD_DEVICE:
Msg = "The value specified by lpLocalName is invalid." ;
break ;
case ERROR_BAD_NET_NAME:
Msg = "The resource name is invalid, or the named resource cannot be located." ;
break ;
case ERROR_BAD_PROFILE:
Msg = "The user profile is in an incorrect format." ;
break ;
case ERROR_BAD_PROVIDER:
Msg = "The value specified by lpProvider does not match any provider." ;
break ;
case ERROR_BUSY:
Msg = "The value specified by lpProvider does not match any provider." ;
break ;
case ERROR_CANCELLED:
Msg = "The connection was cancelled by the user." ;
break ;
case ERROR_CANNOT_OPEN_PROFILE:
Msg = "The system is unable to open the user profile." ;
break ;
case ERROR_DEVICE_ALREADY_REMEMBERED:
Msg = "An entry for the device specified in lpLocalName is already in the user profile." ;
break ;
case ERROR_EXTENDED_ERROR:
Msg = "A network-specific error occured." ;
break ;
case ERROR_INVALID_PASSWORD:
Msg = "The password is invalid." ;
break ;
case ERROR_NO_NET_OR_BAD_PATH:
Msg = "A network component has not started." ;
break ;
case ERROR_NO_NETWORK:
Msg = "No network." ;
break ;
}

if (Msg.Length() > 0)
MessageDlg(Msg, mtError, TMsgDlgButtons() << mbOK, 0) ;
}

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧