函数 NetShareGetInfo return 始终为 2310(此共享不存在)
Function NetShareGetInfo return always 2310 (This share doesn't exist)
我想恢复共享文件夹的属性。我使用 NetShareGetInfo 函数,但它 returns 对我来说是一个 2310 错误。此文件夹不存在。
这是我的代码:
NET_API_STATUS pStatus;
SHARE_INFO_2 pBuffer;
//here status return 2310 - This shared resource does not exist.
pStatus=NetShareGetInfo(nullptr, L"\\PCRT-S35521\sharedFolder", 2, reinterpret_cast<LPBYTE*>(&pBuffer));
有谁知道这个问题可能来自哪里?因为网络路径正确,权限正确
文档说,如果第一个参数(服务器名称)是 NULL
,则使用本地计算机。这就是您的代码返回 NERR_NetNameNotFound
.
的原因
除此之外,您错误地传递了最终参数。您需要额外的间接级别,因为该函数分配缓冲区。
它应该看起来像这样:
NET_API_STATUS pStatus;
SHARE_INFO_2 *pBuffer;
pStatus = NetShareGetInfo(L"PCRT-S35521", L"sharedFolder", 2, (LPBYTE)&pBuffer);
记得按照文档中给出的说明销毁缓冲区:
This buffer is allocated by the system and must be freed using the NetApiBufferFree
function.
我想恢复共享文件夹的属性。我使用 NetShareGetInfo 函数,但它 returns 对我来说是一个 2310 错误。此文件夹不存在。 这是我的代码:
NET_API_STATUS pStatus;
SHARE_INFO_2 pBuffer;
//here status return 2310 - This shared resource does not exist.
pStatus=NetShareGetInfo(nullptr, L"\\PCRT-S35521\sharedFolder", 2, reinterpret_cast<LPBYTE*>(&pBuffer));
有谁知道这个问题可能来自哪里?因为网络路径正确,权限正确
文档说,如果第一个参数(服务器名称)是 NULL
,则使用本地计算机。这就是您的代码返回 NERR_NetNameNotFound
.
除此之外,您错误地传递了最终参数。您需要额外的间接级别,因为该函数分配缓冲区。
它应该看起来像这样:
NET_API_STATUS pStatus;
SHARE_INFO_2 *pBuffer;
pStatus = NetShareGetInfo(L"PCRT-S35521", L"sharedFolder", 2, (LPBYTE)&pBuffer);
记得按照文档中给出的说明销毁缓冲区:
This buffer is allocated by the system and must be freed using the
NetApiBufferFree
function.