Create Network Share with permissions

2019-06-09 21:04发布

问题:

I didn't find any good info or library on the inet, about how to create a network share and set permission for a local group. I'm using c# and Windows Server 2008.

Does anyone have some good resources or sample to point me in the right direction?

回答1:

You can use Pinvoke or WMI,

there is a very nice article on this on Code Project: How to create a file share using .NET framework

the key of the whole thing is the following Windows API:

[DllImport("Netapi32.dll")]
public static extern int NetShareAdd([MarshalAs(UnmanagedType.LPWStr)]
string strServer, Int32 dwLevel, IntPtr buf, IntPtr parm_err);

for using WMI, MSDN "knows": Create method of the Win32_Share Class