我在使用 boost create_directories() 在远程计算机上的共享文件夹上创建目录时遇到问题。我只有读取此共享的权限。但是我使用具有完全读写权限的用户凭据创建连接。
使用 WNetAddConnection2 启用连接。然后应用程序应创建目录“\139.22.XXX.XXX\temp\Test\1”,并使用 WNetCancelConnection2 禁用连接。
代码如下所示:
using namespace boost::filesystem;
typedef boost::filesystem::path Path;
typedef boost::filesystem::basic_filesystem_error<boost::filesystem::path> boost_filesystem_error;
DWORD loginDicomImporter()
{
DWORD dwRetVal;
NETRESOURCE nr;
DWORD dwFlags;
LPTSTR remoteName = _T("\\\\139.22.XXX.XXX\\temp");
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = NULL;
nr.lpRemoteName = remoteName;
nr.lpProvider = NULL;
dwFlags = CONNECT_TEMPORARY;
dwRetVal = WNetAddConnection2(&nr, _T("xxxPWDxxx"), _T("xxxUSERxxx"), dwFlags);
if (dwRetVal == NO_ERROR)
{
return dwRetVal;
}
else
{
return dwRetVal;
}
}
DWORD logoutDicomImporter()
{
DWORD dwResult;
LPCTSTR lpName = _T("\\\\139.22.XXX.XXX\\temp");
dwResult = WNetCancelConnection2(lpName, CONNECT_UPDATE_PROFILE, FALSE);
if (dwResult == NO_ERROR)
{
return dwResult;
}
else if (dwResult == ERROR_NOT_CONNECTED)
{
return dwResult;
}
else
{
return dwResult;
}
}
int main()
{
DWORD loginResult;
std::string directoryPath = "\\\\139.22.XXX.XXX\\temp\\Test\\1";
loginResult = loginDicomImporter();
std::cout << loginResult << std::endl;
try
{
boost::filesystem::create_directories(directoryPath);
}
catch (boost_filesystem_error &e)
{
auto msg = e.what();
return 1;
}
loginResult = logoutDicomImporter();
std::cout << loginResult << std::endl;
}
捕获的异常说“boost::filesystem::create_directory: Access denied:”\139.22.XXX.XXX\temp\Test\1“显然,操作系统拒绝访问。虽然我在创建目录之前启用了完全访问连接。
任何建议如何解决这个问题?