开发过程中的记录,Mark一下吧!
void CTestDlg::OnButtonMapping()
{
// TODO: Add your control notification handler code here
UpdateData( TRUE );
if( m_dir.IsEmpty() )
{
AfxMessageBox("请输入要映射的网络文件夹");
return;
}
if( m_driver.IsEmpty() )
{
AfxMessageBox("请输入映射后的驱动器号");
return;
}
NETRESOURCE net;
net.dwScope = RESOURCE_GLOBALNET;
net.dwType = RESOURCETYPE_DISK;
net.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE;
net.dwUsage = RESOURCEUSAGE_CONNECTABLE;
net.lpLocalName = m_driver.GetBuffer( 0 );
net.lpRemoteName = m_dir.GetBuffer( 0 );
net.lpComment = NULL;
net.lpProvider = NULL;
DWORD Derr;
Derr = WNetAddConnection2(&net, "123", "user01", CONNECT_UPDATE_PROFILE);
if( Derr == NO_ERROR )
{
AfxMessageBox("映射网络驱动器成功!");
DeleteFile("Z:\\test_xx.txt"); //删除一个文件,试试
}
else
{
AfxMessageBox("映射网络驱动器失败!");
}
m_driver.ReleaseBuffer();
m_dir.ReleaseBuffer();
}
WNetCancelConnection2(m_driver,0,false); //这个是取消映射的驱动器。