Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

NativeMethods.NetworkShareManagement.cs 9.1 KiB

8 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. using System.Diagnostics.CodeAnalysis;
  22. using System.Runtime.InteropServices;
  23. using System.Security;
  24. namespace Alphaleonis.Win32.Network
  25. {
  26. partial class NativeMethods
  27. {
  28. /// <summary>Lists all connections made to a shared resource on the server or all connections established from a particular computer.</summary>
  29. /// <returns>
  30. /// If the function succeeds, the return value is NERR_Success.
  31. /// If the function fails, the return value is a system error code.
  32. /// </returns>
  33. /// <remarks>
  34. /// <para>If there is more than one user using this connection, then it is possible to get more than one structure for the same connection, but with a different user name.</para>
  35. /// <para>Administrator, Server or Print Operator, or Power User group membership is required to successfully execute the NetConnectionEnum function.</para>
  36. /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
  37. /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
  38. /// </remarks>
  39. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  40. [DllImport("netapi32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  41. [return: MarshalAs(UnmanagedType.U4)]
  42. internal static extern uint NetConnectionEnum([MarshalAs(UnmanagedType.LPWStr)] string serverName, [MarshalAs(UnmanagedType.LPWStr)] string qualifier, [MarshalAs(UnmanagedType.U4)] uint level, out SafeGlobalMemoryBufferHandle bufPtr, [MarshalAs(UnmanagedType.I4)] int prefMaxLen, [MarshalAs(UnmanagedType.U4)] out uint entriesRead, [MarshalAs(UnmanagedType.U4)] out uint totalEntries, [MarshalAs(UnmanagedType.U4)] out uint resumeHandle);
  43. /// <summary>Forces a resource to close. This function can be used when an error prevents closure by any other means.</summary>
  44. /// <returns>
  45. /// If the function succeeds, the return value is NERR_Success.
  46. /// If the function fails, the return value is a system error code.
  47. /// </returns>
  48. /// <remarks>
  49. /// <para>You should use NetFileClose with caution because it does not write data cached on the client system to the file before closing the file.</para>
  50. /// <para>Only members of the Administrators or Server Operators local group can successfully execute the NetFileEnum function.</para>
  51. /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
  52. /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
  53. /// </remarks>
  54. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  55. [DllImport("netapi32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  56. [return: MarshalAs(UnmanagedType.U4)]
  57. internal static extern uint NetFileClose([MarshalAs(UnmanagedType.LPWStr)] string serverName, [MarshalAs(UnmanagedType.U4)] uint fileid);
  58. /// <summary>Returns information about some or all open files on a server, depending on the parameters specified.</summary>
  59. /// <returns>
  60. /// If the function succeeds, the return value is NERR_Success.
  61. /// If the function fails, the return value is a system error code.
  62. /// </returns>
  63. /// <remarks>
  64. /// <para>Only members of the Administrators or Server Operators local group can successfully execute the NetFileEnum function.</para>
  65. /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
  66. /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
  67. /// </remarks>
  68. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  69. [DllImport("netapi32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  70. [return: MarshalAs(UnmanagedType.U4)]
  71. internal static extern uint NetFileEnum([MarshalAs(UnmanagedType.LPWStr)] string serverName, [MarshalAs(UnmanagedType.LPWStr)] string basepath, [MarshalAs(UnmanagedType.LPWStr)] string username, [MarshalAs(UnmanagedType.U4)] uint level, out SafeGlobalMemoryBufferHandle buffer, [MarshalAs(UnmanagedType.I4)] int prefmaxlen, [MarshalAs(UnmanagedType.U4)] out uint entriesRead, [MarshalAs(UnmanagedType.U4)] out uint totalentries, [MarshalAs(UnmanagedType.U4)] out uint resumeHandle);
  72. /// <summary>Retrieves information about each (hidden) Server Message Block (SMB) resource/share on a server.</summary>
  73. /// <returns>
  74. /// If the function succeeds, the return value is NERR_Success.
  75. /// If the function fails, the return value is a system error code.
  76. /// </returns>
  77. /// <remarks>
  78. /// <para>For interactive users (users who are logged on locally to the machine), no special group membership is required to execute the NetShareEnum function.</para>
  79. /// <para>For non-interactive users, Administrator, Power User, Print Operator, or Server Operator group membership is required to successfully execute the NetShareEnum function at levels 2, 502, and 503. No special group membership is required for level 0 or level 1 calls.</para>
  80. /// <para>This function applies only to Server Message Block (SMB) shares.</para>
  81. /// <para>Windows Server 2003 and Windows XP: For all users, Administrator, Power User, Print Operator, or Server Operator group membership is required to successfully execute the NetShareEnum function at levels 2 and 502.</para>
  82. /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
  83. /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
  84. /// </remarks>
  85. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  86. [DllImport("netapi32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  87. [return: MarshalAs(UnmanagedType.U4)]
  88. internal static extern uint NetShareEnum([MarshalAs(UnmanagedType.LPWStr)] string serverName, [MarshalAs(UnmanagedType.U4)] uint level, out SafeGlobalMemoryBufferHandle bufPtr, [MarshalAs(UnmanagedType.I4)] int prefMaxLen, [MarshalAs(UnmanagedType.U4)] out uint entriesRead, [MarshalAs(UnmanagedType.U4)] out uint totalEntries, [MarshalAs(UnmanagedType.U4)] out uint resumeHandle);
  89. /// <summary>Retrieves information about a particular Server Message Block (SMB) shared resource on a server.</summary>
  90. /// <returns>
  91. /// If the function succeeds, the return value is NERR_Success.
  92. /// If the function fails, the return value is a system error code.
  93. /// </returns>
  94. /// <remarks>
  95. /// <para>For interactive users (users who are logged on locally to the machine), no special group membership is required to execute the NetShareGetInfo function.</para>
  96. /// <para>For non-interactive users, Administrator, Power User, Print Operator, or Server Operator group membership is required to successfully execute the NetShareGetInfo function at levels 2, 502, and 503.</para>
  97. /// <para>This function applies only to Server Message Block (SMB) shares.</para>
  98. /// <para>Windows Server 2003 and Windows XP: For all users, Administrator, Power User, Print Operator, or Server Operator group membership is required to successfully execute the NetShareGetInfo function at levels 2 and 502.</para>
  99. /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
  100. /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
  101. /// </remarks>
  102. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  103. [DllImport("netapi32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  104. [return: MarshalAs(UnmanagedType.U4)]
  105. internal static extern uint NetShareGetInfo([MarshalAs(UnmanagedType.LPWStr)] string serverName, [MarshalAs(UnmanagedType.LPWStr)] string netName, [MarshalAs(UnmanagedType.U4)] uint level, out SafeGlobalMemoryBufferHandle lpBuffer);
  106. }
  107. }