private static DfsInfo GetDfsInfoCore(bool getFromClient, string dfsName, string serverName, string shareName) { if (!Filesystem.NativeMethods.IsAtLeastWindowsVista) { throw new PlatformNotSupportedException(Resources.Requires_Windows_Vista_Or_Higher); } if (Utils.IsNullOrWhiteSpace(dfsName)) { throw new ArgumentNullException("dfsName"); } serverName = Utils.IsNullOrWhiteSpace(serverName) ? null : serverName; shareName = Utils.IsNullOrWhiteSpace(shareName) ? null : shareName; SafeGlobalMemoryBufferHandle safeBuffer; // Level 9 = DFS_INFO_9 uint lastError = getFromClient ? NativeMethods.NetDfsGetClientInfo(dfsName, serverName, shareName, 9, out safeBuffer) : NativeMethods.NetDfsGetInfo(dfsName, null, null, 9, out safeBuffer); if (lastError == Win32Errors.NERR_Success) { return(new DfsInfo(safeBuffer.PtrToStructure <NativeMethods.DFS_INFO_9>(0))); } throw new NetworkInformationException((int)lastError); }
internal static DfsInfo GetDfsInfoCore(bool getFromClient, string dfsName, string serverName, string shareName) { if (!Filesystem.NativeMethods.IsAtLeastWindowsVista) { throw new PlatformNotSupportedException(new Win32Exception((int)Win32Errors.ERROR_OLD_WIN_VERSION).Message); } if (Utils.IsNullOrWhiteSpace(dfsName)) { throw new ArgumentNullException("dfsName"); } serverName = !Utils.IsNullOrWhiteSpace(serverName) ? serverName : null; shareName = !Utils.IsNullOrWhiteSpace(shareName) ? shareName : null; SafeGlobalMemoryBufferHandle safeBuffer; // Level 9 = DFS_INFO_9 var lastError = getFromClient ? NativeMethods.NetDfsGetClientInfo(dfsName, serverName, shareName, 9, out safeBuffer) : NativeMethods.NetDfsGetInfo(dfsName, null, null, 9, out safeBuffer); if (lastError == Win32Errors.NERR_Success) { return(new DfsInfo(safeBuffer.PtrToStructure <NativeMethods.DFS_INFO_9>(0))); } throw new NetworkInformationException((int)lastError); }
private static DfsInfo GetDfsInfoInternal(bool getFromClient, string dfsName, string serverName, string shareName) { if (!Filesystem.NativeMethods.IsAtLeastWindowsVista) { throw new PlatformNotSupportedException(Resources.RequiresWindowsVistaOrHigher); } if (Utils.IsNullOrWhiteSpace(dfsName)) { throw new ArgumentNullException("dfsName"); } serverName = Utils.IsNullOrWhiteSpace(serverName) ? null : serverName; shareName = Utils.IsNullOrWhiteSpace(shareName) ? null : shareName; // MSDN: This buffer is allocated by the system (the API). var buffer = IntPtr.Zero; try { // Level 4 = DFS_INFO_4 uint lastError = getFromClient ? NativeMethods.NetDfsGetClientInfo(dfsName, serverName, shareName, 4, out buffer) : NativeMethods.NetDfsGetInfo(dfsName, null, null, 4, out buffer); if (lastError == Win32Errors.NERR_Success) { return(new DfsInfo(Utils.MarshalPtrToStructure <NativeMethods.DfsInfo4>(0, buffer))); } throw new NetworkInformationException((int)lastError); } finally { if (buffer != IntPtr.Zero) { NativeMethods.NetApiBufferFree(buffer); } } }