public static int NetShareSetInfo_1005(string ServerName, string ShareName, SHARE_INFO_1005 shi1005_Info) // Int32 Shi1005_flags { Int32 level = 1005; Int32 err; IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(shi1005_Info)); Marshal.StructureToPtr(shi1005_Info, ptr, false); var result = unmanaged.NetShareSetInfo(ServerName, ShareName, level, ptr, out err); return(result); }
public static SHARE_INFO_1005 NetShareGetInfo_1005(string ServerName, string ShareName) { Int32 level = 1005; IntPtr lShareInfo = IntPtr.Zero; SHARE_INFO_1005 shi1005_Info = new SHARE_INFO_1005(); Int32 result = unmanaged.NetShareGetInfo(ServerName, ShareName, level, ref lShareInfo); if ((Share_ReturnValue)result == Share_ReturnValue.NERR_Success) { shi1005_Info = (SHARE_INFO_1005)Marshal.PtrToStructure(lShareInfo, typeof(SHARE_INFO_1005)); } else { throw new Exception("Unable to get 1005 structure. Function returned: " + (Share_ReturnValue)result); } return(shi1005_Info); }
public static int GetShareCachingInfo(string ComputerName, string ShareName) { IntPtr ptr = IntPtr.Zero; int errCode = 0; errCode = NetShareGetInfo(ComputerName, ShareName, 1005, out ptr); if (errCode == (int)NetError.NERR_Success) { SHARE_INFO_1005 shareInfo = (SHARE_INFO_1005)Marshal.PtrToStructure(ptr, typeof(SHARE_INFO_1005)); NetApiBufferFree(ptr); return(shareInfo.shi1005_flags); } else { throw new Win32Exception(errCode); } }
public static void SetShareCachingInfo(string ComputerName, string ShareName, int ShareFlags) { IntPtr ptr = IntPtr.Zero; int param_Err = 0; int errCode = 0; SHARE_INFO_1005 shareInfo = new SHARE_INFO_1005(); shareInfo.shi1005_flags = ShareFlags; ptr = Marshal.AllocHGlobal(Marshal.SizeOf(shareInfo)); Marshal.StructureToPtr(shareInfo, ptr, true); errCode = NetShareSetInfo(ComputerName, ShareName, 1005, ptr, out param_Err); if (errCode == (int)NetError.NERR_Success) { SHARE_INFO_1005 shareInfo2 = (SHARE_INFO_1005)Marshal.PtrToStructure(ptr, typeof(SHARE_INFO_1005)); NetApiBufferFree(ptr); } else { throw new Win32Exception(errCode); } }