Click to See Complete Forum and Search --> : How to set share permissions for shared folder programmatically?
maggiezhao
February 17th, 2003, 12:38 PM
I use
net share
to share a folder from command line, but
I don't know how to set share permissions for shared folder (not permission for security) programmatically?
Thanks a lot!
Mick
February 17th, 2003, 12:49 PM
I think you want to look at the NetShareAdd(...) function, and grouped functions for shares, in the IDE help or on MSDN.microsoft.com
maggiezhao
February 17th, 2003, 02:53 PM
Originally posted by Mick_2002
I think you want to look at the NetShareAdd(...) function, and grouped functions for shares, in the IDE help or on MSDN.microsoft.com :p
maggiezhao
February 17th, 2003, 03:08 PM
The following are my C++ code (Unicode) to create a
share folder. It created shared folder successfully,
but p.shi2_permissions = ACCESS_READ;
seems not work.
I want to deny permissions for everyone user!!!
In MSDN:
shi2_permissions
Specifies a DWORD value that indicates the shared resource's permissions for servers running with share-level security. A server running user-level security ignores this member. This member can be one or more of the following values. Calls to the NetShareSetInfo function ignore this member.
Any further help will be appreciated!
Thanks!
// XpShare.cpp : Defines the entry point for the console //application.
//
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <Lmshare.h>
extern "C" {
#include <Lm.h>
}
int _tmain(int argc, _TCHAR* argv[])
{
NET_API_STATUS res;
SHARE_INFO_2 p;
DWORD parm_err = 0;
//
// Fill in the SHARE_INFO_2 structure.
//
p.shi2_netname = TEXT("TESTSHARE_A");
p.shi2_type = STYPE_DISKTREE; // disk drive
p.shi2_remark = TEXT("created by NetShareAdd");
p.shi2_permissions = ACCESS_READ;
p.shi2_max_uses = 4;
p.shi2_current_uses = 0;
p.shi2_path = TEXT("C:\\A");
p.shi2_passwd = NULL; // no password
//
// Call the NetShareAdd function,
// specifying level 2.
//
res=NetShareAdd(NULL, 2, (LPBYTE) &p, &parm_err);
//
// If the call succeeds, inform the user.
//
if(res==0)
printf("Share created.\n");
// Otherwise, print an error,
// and identify the parameter in error.
//
else
{
printf("Error: %u\tparmerr=%u\n", res, parm_err);
}
return 0;
}
Fuzzy_NZ
June 16th, 2005, 04:11 AM
The following are my C++ code (Unicode) to create a
share folder. It created shared folder successfully,
but p.shi2_permissions = ACCESS_READ;
seems not work.
I want to deny permissions for everyone user!!!
In MSDN:
shi2_permissions
Specifies a DWORD value that indicates the shared resource's permissions for servers running with share-level security. A server running user-level security ignores this member. This member can be one or more of the following values. Calls to the NetShareSetInfo function ignore this member.
Any further help will be appreciated!
Thanks!
// XpShare.cpp : Defines the entry point for the console //application.
//
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <Lmshare.h>
extern "C" {
#include <Lm.h>
}
int _tmain(int argc, _TCHAR* argv[])
{
NET_API_STATUS res;
SHARE_INFO_2 p;
...
res=NetShareAdd(NULL, 2, (LPBYTE) &p, &parm_err);
...
}
firstly change SHARE_INFO_2 to SHARE_INFO_502
and change res=NetShareAdd(NULL, 2, (LPBYTE) &p, &parm_err);
to res=NetShareAdd(NULL, 502, (LPBYTE) &p, &parm_err);
then you will need to set the security discriptor in the SHARE_INFO_502 structor
you should also note there is a NetShareSetInfo that will set the permissions for a share that exists
p.shi2_permissions is only used for Simple file sharing not NT file sharing
Dont ask me how make the file discriptor work, I cant even get the NetShareAdd function to work, I keep getting the these errors 123 and 1320 (I think) and have no idea what they are
If you prog works (sharing the folder) would you mind emailing me a compiled copy so i can test it on my computer
email address is fuz_king@hotmail.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.