Last active
January 31, 2020 22:24
-
-
Save shelld0n/fc0c3e2455e7696afda23f7ec0e5e256 to your computer and use it in GitHub Desktop.
Adjust Token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Luid Structure Definition | |
[StructLayout(LayoutKind.Sequential)] | |
public struct LUID | |
{ | |
public UInt32 LowPart; | |
public Int32 HighPart; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct LUID_AND_ATTRIBUTES | |
{ | |
public LUID Luid; | |
public UInt32 Attributes; | |
public const UInt32 SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001; | |
public const UInt32 SE_PRIVILEGE_ENABLED = 0x00000002; | |
public const UInt32 SE_PRIVILEGE_REMOVED = 0x00000004; | |
public const UInt32 SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000; | |
} | |
private const int ANYSIZE_ARRAY = 1; | |
// Token_Privileges Structure Definition | |
public struct TOKEN_PRIVILEGES | |
{ | |
public int PrivilegeCount; | |
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ANYSIZE_ARRAY)] | |
public LUID_AND_ATTRIBUTES[] Privileges; | |
} | |
// AdjustTokenPrivileges | |
[DllImport("advapi32.dll", SetLastError = true)] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
public static extern bool AdjustTokenPrivileges(IntPtr TokenHandle, | |
[MarshalAs(UnmanagedType.Bool)]bool DisableAllPrivileges, | |
ref TOKEN_PRIVILEGES NewState, | |
UInt32 BufferLengthInBytes, | |
ref TOKEN_PRIVILEGES PreviousState, | |
out UInt32 ReturnLengthInBytes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment