25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

7 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // <copyright file="NativeMethods.cs" company="Nick Lowe">
  2. // Copyright © Nick Lowe 2009
  3. // </copyright>
  4. // <author>Nick Lowe</author>
  5. // <email>nick@int-r.net</email>
  6. // <url>http://processprivileges.codeplex.com/</url>
  7. namespace ProcessPrivileges
  8. {
  9. using System;
  10. using System.Runtime.ConstrainedExecution;
  11. using System.Runtime.InteropServices;
  12. using System.Security;
  13. using System.Text;
  14. /// <summary>Static class containing Win32 native methods.</summary>
  15. internal static class NativeMethods
  16. {
  17. internal const int ErrorInsufficientBuffer = 122;
  18. private const string AdvApi32 = "advapi32.dll";
  19. private const string Kernel32 = "kernel32.dll";
  20. [DllImport(AdvApi32, SetLastError = true),
  21. SuppressUnmanagedCodeSecurity]
  22. [return: MarshalAs(UnmanagedType.Bool)]
  23. internal static extern bool AdjustTokenPrivileges(
  24. [In] AccessTokenHandle accessTokenHandle,
  25. [In, MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges,
  26. [In] ref TokenPrivilege newState,
  27. [In] int bufferLength,
  28. [In, Out] ref TokenPrivilege previousState,
  29. [In, Out] ref int returnLength);
  30. [DllImport(Kernel32, SetLastError = true),
  31. ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail),
  32. SuppressUnmanagedCodeSecurity]
  33. [return: MarshalAs(UnmanagedType.Bool)]
  34. internal static extern bool CloseHandle(
  35. [In] IntPtr handle);
  36. [DllImport(AdvApi32, CharSet = CharSet.Unicode, SetLastError = true),
  37. SuppressUnmanagedCodeSecurity]
  38. [return: MarshalAs(UnmanagedType.Bool)]
  39. internal static extern bool LookupPrivilegeName(
  40. [In] string systemName,
  41. [In] ref Luid luid,
  42. [In, Out] StringBuilder name,
  43. [In, Out] ref int nameLength);
  44. [DllImport(AdvApi32, CharSet = CharSet.Unicode, SetLastError = true),
  45. SuppressUnmanagedCodeSecurity]
  46. [return: MarshalAs(UnmanagedType.Bool)]
  47. internal static extern bool LookupPrivilegeValue(
  48. [In] string systemName,
  49. [In] string name,
  50. [In, Out] ref Luid luid);
  51. [DllImport(AdvApi32, SetLastError = true),
  52. SuppressUnmanagedCodeSecurity]
  53. [return: MarshalAs(UnmanagedType.Bool)]
  54. internal static extern bool GetTokenInformation(
  55. [In] AccessTokenHandle accessTokenHandle,
  56. [In] TokenInformationClass tokenInformationClass,
  57. [Out] IntPtr tokenInformation,
  58. [In] int tokenInformationLength,
  59. [In, Out] ref int returnLength);
  60. [DllImport(AdvApi32, SetLastError = true),
  61. SuppressUnmanagedCodeSecurity]
  62. [return: MarshalAs(UnmanagedType.Bool)]
  63. internal static extern bool OpenProcessToken(
  64. [In] ProcessHandle processHandle,
  65. [In] TokenAccessRights desiredAccess,
  66. [In, Out] ref IntPtr tokenHandle);
  67. }
  68. }