Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (
ByVal TokenHandle As IntPtr, _
ByVal DisableAllPrivileges As Boolean, _
ByRef NewState As TOKEN_PRIVILEGES, _
ByVal BufferLength As Integer, _
ByRef PreviousState As TOKEN_PRIVILEGES, _
ByVal ReturnLength As IntPtr) As Boolean
If SetLastError is set to true, get the error with this.
int lastError = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
Console.Error.WriteLine("NativeErr: " + lastError);
Then use Error lookup tool for troubleshooting it can be downloaded from MS, ''Err.exe'' I think...
C# Sample Code:
//This snippet is tested on WinXP and Vista, only needed in Vista when using SetTimeZoneInformation
Public Class AdjPriv()
{
Const TOKEN_QUERY As Integer = &H8
Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20
Const SE_RESTORE_NAME As String = "SeRestorePrivilege"
Dim hProc, hToken As IntPtr
Dim luid_Restore, As Long
Dim tp As New TOKEN_PRIVILEGES
' get the current process's token
hProc = Process.GetCurrentProcess().Handle
hToken = IntPtr.Zero
If Not OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken) Then
Return False
End If
' get the LUID for the Restore privilege (provided it already exist)
luid_Restore = 0
If Not LookupPrivilegeValue(Nothing, SE_RESTORE_NAME, luid_Restore) Then
Return False
End If
' enable the privileges
If Not AdjustTokenPrivileges(hToken, False, tp, 0, IntPtr.Zero, IntPtr.Zero) Then
Return False
End If
'good
Alternative Managed API:
Do you know one? Please contribute it!
Contains information about a set of privileges for an access token.
3/24/2021 8:20:52 AM - -142.126.162.230
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).