编程实现映射网络驱动器

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

void __fastcall TForm1::Button1Click(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) ;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
DWORD flag=WNetCancelConnection2(txtLocalName->Text.c_str(), 0, FALSE);

}

net use

相关文档
最新文档