Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

NativeMethods.WindowsNetworking.cs 4.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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;
  22. using System.Diagnostics.CodeAnalysis;
  23. using System.Runtime.InteropServices;
  24. using System.Security;
  25. using System.Text;
  26. namespace Alphaleonis.Win32.Network
  27. {
  28. partial class NativeMethods
  29. {
  30. /// <summary>The WNetCancelConnection function cancels an existing network connection. You can also call the function to remove remembered network connections that are not currently connected.</summary>
  31. /// <returns>
  32. /// If the function succeeds, the return value is <see cref="Win32Errors.NO_ERROR"/>
  33. /// If the function fails, the return value is a system error code.
  34. /// </returns>
  35. /// <remarks>
  36. /// <para>Minimum supported client: Windows 2000 Professional [desktop apps only]</para>
  37. /// <para>Minimum supported server: Windows 2000 Server [desktop apps only]</para>
  38. /// </remarks>
  39. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  40. [DllImport("mpr.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "WNetCancelConnection2W"), SuppressUnmanagedCodeSecurity]
  41. [return: MarshalAs(UnmanagedType.U4)]
  42. internal static extern uint WNetCancelConnection([MarshalAs(UnmanagedType.LPWStr)] string lpName, Connect dwFlags, [MarshalAs(UnmanagedType.Bool)] bool fForce);
  43. /// <summary>The WNetGetUniversalName function takes a drive-based path for a network resource and returns an information structure that contains a more universal form of the name.</summary>
  44. /// <returns>
  45. /// If the function succeeds, the return value is <see cref="Win32Errors.NO_ERROR"/>
  46. /// If the function fails, the return value is a system error code.
  47. /// </returns>
  48. /// <remarks>
  49. /// <para>Minimum supported client: Windows 2000 Professional [desktop apps only]</para>
  50. /// <para>Minimum supported server: Windows 2000 Server [desktop apps only]</para>
  51. /// </remarks>
  52. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  53. [DllImport("mpr.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "WNetGetUniversalNameW"), SuppressUnmanagedCodeSecurity]
  54. [return: MarshalAs(UnmanagedType.U4)]
  55. internal static extern uint WNetGetUniversalName([MarshalAs(UnmanagedType.LPWStr)] string lpLocalPath, [MarshalAs(UnmanagedType.U4)] uint dwInfoLevel, SafeGlobalMemoryBufferHandle lpBuffer, [MarshalAs(UnmanagedType.U4)] out uint lpBufferSize);
  56. /// <summary>The WNetUseConnection function creates a connection to a network resource. The function can redirect a local device to a network resource.</summary>
  57. /// <returns>
  58. /// If the function succeeds, the return value is <see cref="Win32Errors.NO_ERROR"/>
  59. /// If the function fails, the return value is a system error code.
  60. /// </returns>
  61. /// <remarks>
  62. /// <para>Minimum supported client: Windows 2000 Professional [desktop apps only]</para>
  63. /// <para>Minimum supported server: Windows 2000 Server [desktop apps only]</para>
  64. /// </remarks>
  65. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  66. [DllImport("mpr.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "WNetUseConnectionW"), SuppressUnmanagedCodeSecurity]
  67. [return: MarshalAs(UnmanagedType.U4)]
  68. internal static extern uint WNetUseConnection(IntPtr hwndOwner, [MarshalAs(UnmanagedType.Struct)] ref NETRESOURCE lpNetResource, [MarshalAs(UnmanagedType.LPWStr)] string lpPassword, [MarshalAs(UnmanagedType.LPWStr)] string lpUserId, [MarshalAs(UnmanagedType.U4)] Connect dwFlags, StringBuilder lpAccessName, [MarshalAs(UnmanagedType.U4)] out uint lpBufferSize, [MarshalAs(UnmanagedType.U4)] out uint lpResult);
  69. // Note: When NETRESOURCE is struct: use ref, when NETRESOURCE is class: ommit ref.
  70. }
  71. }