How to create read-only network share programmatic

2019-02-19 15:19发布

问题:

How does one create an administrative network share [1] with read-only permissions from C/C++ or Python under Windows XP?

[1] Necessary in order to access C:\Program Files over the share.

回答1:

First create the share with NetShareAdd(). This will share the directory with a null ACL, which is equavalent to allowing everyone full access. It is not possible to configure permissions with NetShareAdd on Windows.

Once the share has been created, get the security descriptor for the share by calling GetNamedSecurityInfoW() passing in the share name, SE_LMSHARE as the ObjectType, and DACL_SECURITY_INFORMATION as the SecurityInfo. Once you have the descriptor, use the normal Windows security calls to configure the ACL.



回答2:

Take a look at NetShareAdd() for C/C++ (the MSDN includes an example program at the end of the page).