Reputation: 167
I'm trying to use NetShareDelEx
but I'm getting error 124 which is ERROR_INVALID_LEVEL
.
For testing purpose I first add a share with NetShareAdd
which is successful. Then I try to remove it. My code is:
LPCWSTR sharePath = L"C:\\SharedFolderEx";
SHARE_INFO_2 shareInfo;
ZeroMemory(&shareInfo, sizeof(SHARE_INFO_2));
shareInfo.shi2_netname = L"SharedFolderEx";
shareInfo.shi2_type = STYPE_DISKTREE;
shareInfo.shi2_remark = L"Shared Folder for testing";
shareInfo.shi2_permissions = ACCESS_READ | ACCESS_WRITE | ACCESS_DELETE;
shareInfo.shi2_max_uses = -1;
shareInfo.shi2_path = (LPWSTR)sharePath;
shareInfo.shi2_passwd = NULL;
DWORD parmErr;
DWORD status = NetShareAdd(NULL, 2, (LPBYTE)&shareInfo, &parmErr);
if(status != NERR_Success && status != NERR_DuplicateShare) {
printf("NetShareAdd failed, Error code: %d\n", status);
return;
}
status = NetShareDelEx(NULL, 2, (LPBYTE)&shareInfo);
if(status != NERR_Success) {
printf("NetShareDelEx failed, Error code: %d\n", status);
return;
}
I also tried for the NetShareDelEx
call to use SHARE_INFO_0
or SHARE_INFO_1
but I got the same error code (124). I have no issue if I use NetShareDel
or NetShareDelSticky
but I need to use NetShareDelEx
.
What I'm doing wrong?
Upvotes: 2
Views: 71
Reputation: 4040
According to the Doc:NetShareDelEx function
If 0, 1, 2, or 502 is specified for the level parameter, the buf parameter points to a SHARE_INFO_0, SHARE_INFO_1, SHARE_INFO_2, or SHARE_INFO_502 structure, and the shi0_netname, shi1_netname, shi2_netname, or shi502_netname member of that structure is used; the other members are ignored.
I suggest you could try to just use the shi2_netname
and ignore the other member.
Upvotes: 1