To change these settings, you can use the NetShareSetInfo function , available in the Windows SDK at level 1005.
All flags are defined here, but note that the documentation does not display SHI1005_FLAGS_ENCRYPT_DATA
(0x08000), which is actually located in the corresponding Windows LMERR.H header file.
Here is an example demonstrating how to use it in a C # console application:
class Program { static void Main(string[] args) {
Here is the NetShareUtilities class that P / Invoke uses to access the Windows API:
public static class NetShareUtilities { [DllImport("netapi32.dll")] private extern static int NetShareSetInfo([MarshalAs(UnmanagedType.LPWStr)] string servername, [MarshalAs(UnmanagedType.LPWStr)] string netname, int level, ref SHI1005_FLAGS buf, IntPtr parm_err); [DllImport("netapi32.dll")] private extern static int NetShareGetInfo([MarshalAs(UnmanagedType.LPWStr)] string servername, [MarshalAs(UnmanagedType.LPWStr)] string netname, int level, out IntPtr bufptr); [DllImport("netapi32.dll")] private static extern IntPtr NetApiBufferFree(IntPtr Buffer); public static SHI1005_FLAGS Get1005Flags(string serverName, string name) { IntPtr ptr; int err = NetShareGetInfo(serverName, name, 1005, out ptr); if (err != 0) throw new Win32Exception(err); var flags = (SHI1005_FLAGS)Marshal.ReadInt32(ptr); NetApiBufferFree(ptr); return flags; } public static void Set1005Flags(string serverName, string name, SHI1005_FLAGS flags) {
source share