看看shell 调用  net use  z:  \\server1\cdrom也可以呀~~

解决方案 »

  1.   

    void CMountDlg::OnMountButton() 

    // TODO: Add your control notification handler code here 
    char netpath[MAX_PATH];
    //输入的网络路径 m_NetpathEdit.GetWindowText(netpath, sizeof(netpath)); 
    char drv[MAX_PATH]; 
    //本地的驱动器盘符 m_DriveEdit.GetWindowText(drv, sizeof(drv)); 
    NETRESOURCE netres; netres.dwScope=RESOURCE_GLOBALNET; 
    netres.dwType=RESOURCETYPE_ANY; 
    netres.dwDisplayType=RESOURCEDISPLAYTYPE_GENERIC; 
    netres.dwUsage=RESOURCEUSAGE_CONNECTABLE; 
    netres.lpLocalName=drv; netres.lpRemoteName=netpath; 
    netres.lpComment=NULL; netres.lpProvider=NULL; 
    DWORD rslt=WNetAddConnection2(&netres, NULL, NULL, 0); 
    CString str; 
    str.Format("WNetAddConnection2() return code=%d", rslt); 
    MessageBox(str); 

    取消网络驱动器的映射 
    void CMountDlg::OnUnmountButton() 
    {
    // TODO: Add your control notification handler code here 
    char drv[MAX_PATH]; 
    //本地的驱动器盘符 
    m_DriveEdit.GetWindowText(drv, sizeof(drv)); 
    DWORD rslt=WNetCancelConnection2(drv, 0, FALSE); 
    CString str; 
    str.Format("WNetCancelConnection2() return code=%d", rslt); 
    MessageBox(str); 
    //显示信息成功与否 return code =0 成功 否则 建立失败 

      

  2.   

    Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
    Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    Const WN_SUCCESS = 0 
    Const WN_NET_ERROR = 2 
    Const WN_BAD_PASSWORD = 6 
    Function AddConnection(MyShareName As String, MyPWD As String, UseLetter As String) As Integer
        On Local Error GoTo AddConnection_Err
        AddConnection = WNetAddConnection(MyShareName, MyPWD, UseLetter)
    AddConnection_End:
        Exit Function
    AddConnection_Err:
        AddConnection = Err
        MsgBox Error$
        Resume AddConnection_End
    End Function
    Function CancelConnection(DriveLetter As String, Force As Integer) As Integer
        On Local Error GoTo CancelConnection_Err
        CancelConnection = WNetCancelConnection(DriveLetter, Force)
    CancelConnection_End:
        Exit Function
    CancelConnection_Err:
        CancelConnection = Err
        MsgBox Error$
        Resume CancelConnection_End
    End Function添加一个网络驱动器:
    variable = AddConnection(<SharePath>, <Password>, <DriveLetter>)
    删除一个网络驱动器:
    varible = CancelConnection(<SharePath, <Force>)