File: _generated\0\LibraryImports.g.cs
Web Access
Project: src\runtime\src\libraries\System.Security.AccessControl\src\System.Security.AccessControl.csproj (System.Security.AccessControl)
// <auto-generated/>
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial bool LookupPrivilegeValue(string lpSystemName, string lpName, out global::Interop.Advapi32.LUID lpLuid)
        {
            unsafe
            {
                int __lastError;
                lpLuid = default;
                bool __retVal;
                int __retVal_native;
                // Pin - Pin data in preparation for calling the P/Invoke.
                fixed (global::Interop.Advapi32.LUID* __lpLuid_native = &lpLuid)
                fixed (void* __lpName_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(lpName))
                fixed (void* __lpSystemName_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(lpSystemName))
                {
                    global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                    __retVal_native = __PInvoke((ushort*)__lpSystemName_native, (ushort*)__lpName_native, __lpLuid_native);
                    __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                }
 
                // Unmarshal - Convert native data to managed data.
                __retVal = __retVal_native != 0;
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "LookupPrivilegeValueW", ExactSpelling = true, CharSet = global::System.Runtime.InteropServices.CharSet.Unicode)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke(ushort* __lpSystemName_native, ushort* __lpName_native, global::Interop.Advapi32.LUID* __lpLuid_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial bool RevertToSelf()
        {
            unsafe
            {
                int __lastError;
                bool __retVal;
                int __retVal_native;
                {
                    global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                    __retVal_native = __PInvoke();
                    __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                }
 
                // Unmarshal - Convert native data to managed data.
                __retVal = __retVal_native != 0;
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "RevertToSelf", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke();
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial bool ConvertSdToStringSd(byte[] securityDescriptor, uint requestedRevision, uint securityInformation, out nint resultString, ref uint resultStringLength)
        {
            unsafe
            {
                int __lastError;
                resultString = default;
                bool __retVal;
                int __retVal_native;
                // Pin - Pin data in preparation for calling the P/Invoke.
                fixed (uint* __resultStringLength_native = &resultStringLength)
                fixed (nint* __resultString_native = &resultString)
                fixed (void* __securityDescriptor_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<byte, byte>.ManagedToUnmanagedIn.GetPinnableReference(securityDescriptor))
                {
                    global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                    __retVal_native = __PInvoke((byte*)__securityDescriptor_native, requestedRevision, securityInformation, __resultString_native, __resultStringLength_native);
                    __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                }
 
                // Unmarshal - Convert native data to managed data.
                __retVal = __retVal_native != 0;
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "ConvertSecurityDescriptorToStringSecurityDescriptorW", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke(byte* __securityDescriptor_native, uint __requestedRevision_native, uint __securityInformation_native, nint* __resultString_native, uint* __resultStringLength_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial bool ConvertStringSdToSd(string stringSd, uint stringSdRevision, out nint resultSd, ref uint resultSdLength)
        {
            unsafe
            {
                int __lastError;
                resultSd = default;
                bool __retVal;
                int __retVal_native;
                // Pin - Pin data in preparation for calling the P/Invoke.
                fixed (uint* __resultSdLength_native = &resultSdLength)
                fixed (nint* __resultSd_native = &resultSd)
                fixed (void* __stringSd_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(stringSd))
                {
                    global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                    __retVal_native = __PInvoke((ushort*)__stringSd_native, stringSdRevision, __resultSd_native, __resultSdLength_native);
                    __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                }
 
                // Unmarshal - Convert native data to managed data.
                __retVal = __retVal_native != 0;
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "ConvertStringSecurityDescriptorToSecurityDescriptorW", ExactSpelling = true, CharSet = global::System.Runtime.InteropServices.CharSet.Unicode)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke(ushort* __stringSd_native, uint __stringSdRevision_native, nint* __resultSd_native, uint* __resultSdLength_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static unsafe partial uint GetSecurityInfoByHandle(global::System.Runtime.InteropServices.SafeHandle handle, uint objectType, uint securityInformation, nint* sidOwner, nint* sidGroup, nint* dacl, nint* sacl, nint* securityDescriptor)
        {
            unsafe
            {
                nint __handle_native = default;
                uint __retVal = default;
                // Setup - Perform required setup.
                global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller<global::System.Runtime.InteropServices.SafeHandle>.ManagedToUnmanagedIn __handle_native__marshaller = new();
                try
                {
                    // Marshal - Convert managed data to native data.
                    __handle_native__marshaller.FromManaged(handle);
                    {
                        // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned.
                        __handle_native = __handle_native__marshaller.ToUnmanaged();
                        __retVal = __PInvoke(__handle_native, objectType, securityInformation, sidOwner, sidGroup, dacl, sacl, securityDescriptor);
                    }
                }
                finally
                {
                    // CleanupCallerAllocated - Perform cleanup of caller allocated resources.
                    __handle_native__marshaller.Free();
                }
 
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "GetSecurityInfo", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe uint __PInvoke(nint __handle_native, uint __objectType_native, uint __securityInformation_native, nint* __sidOwner_native, nint* __sidGroup_native, nint* __dacl_native, nint* __sacl_native, nint* __securityDescriptor_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial uint SetSecurityInfoByHandle(global::System.Runtime.InteropServices.SafeHandle handle, uint objectType, uint securityInformation, byte[] owner, byte[] group, byte[] dacl, byte[] sacl)
        {
            unsafe
            {
                int __lastError;
                nint __handle_native = default;
                uint __retVal = default;
                // Setup - Perform required setup.
                global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller<global::System.Runtime.InteropServices.SafeHandle>.ManagedToUnmanagedIn __handle_native__marshaller = new();
                try
                {
                    // Marshal - Convert managed data to native data.
                    __handle_native__marshaller.FromManaged(handle);
                    // Pin - Pin data in preparation for calling the P/Invoke.
                    fixed (void* __sacl_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<byte, byte>.ManagedToUnmanagedIn.GetPinnableReference(sacl))
                    fixed (void* __dacl_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<byte, byte>.ManagedToUnmanagedIn.GetPinnableReference(dacl))
                    fixed (void* __group_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<byte, byte>.ManagedToUnmanagedIn.GetPinnableReference(group))
                    fixed (void* __owner_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<byte, byte>.ManagedToUnmanagedIn.GetPinnableReference(owner))
                    {
                        // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned.
                        __handle_native = __handle_native__marshaller.ToUnmanaged();
                        global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                        __retVal = __PInvoke(__handle_native, objectType, securityInformation, (byte*)__owner_native, (byte*)__group_native, (byte*)__dacl_native, (byte*)__sacl_native);
                        __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                    }
                }
                finally
                {
                    // CleanupCallerAllocated - Perform cleanup of caller allocated resources.
                    __handle_native__marshaller.Free();
                }
 
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "SetSecurityInfo", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe uint __PInvoke(nint __handle_native, uint __objectType_native, uint __securityInformation_native, byte* __owner_native, byte* __group_native, byte* __dacl_native, byte* __sacl_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial uint GetSecurityInfoByName(string name, uint objectType, uint securityInformation, out nint sidOwner, out nint sidGroup, out nint dacl, out nint sacl, out nint securityDescriptor)
        {
            unsafe
            {
                int __lastError;
                sidOwner = default;
                sidGroup = default;
                dacl = default;
                sacl = default;
                securityDescriptor = default;
                uint __retVal;
                // Pin - Pin data in preparation for calling the P/Invoke.
                fixed (nint* __securityDescriptor_native = &securityDescriptor)
                fixed (nint* __sacl_native = &sacl)
                fixed (nint* __dacl_native = &dacl)
                fixed (nint* __sidGroup_native = &sidGroup)
                fixed (nint* __sidOwner_native = &sidOwner)
                fixed (void* __name_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(name))
                {
                    global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                    __retVal = __PInvoke((ushort*)__name_native, objectType, securityInformation, __sidOwner_native, __sidGroup_native, __dacl_native, __sacl_native, __securityDescriptor_native);
                    __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                }
 
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "GetNamedSecurityInfoW", ExactSpelling = true, CharSet = global::System.Runtime.InteropServices.CharSet.Unicode)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe uint __PInvoke(ushort* __name_native, uint __objectType_native, uint __securityInformation_native, nint* __sidOwner_native, nint* __sidGroup_native, nint* __dacl_native, nint* __sacl_native, nint* __securityDescriptor_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial uint SetSecurityInfoByName(string name, uint objectType, uint securityInformation, byte[] owner, byte[] group, byte[] dacl, byte[] sacl)
        {
            unsafe
            {
                int __lastError;
                uint __retVal;
                // Pin - Pin data in preparation for calling the P/Invoke.
                fixed (void* __sacl_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<byte, byte>.ManagedToUnmanagedIn.GetPinnableReference(sacl))
                fixed (void* __dacl_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<byte, byte>.ManagedToUnmanagedIn.GetPinnableReference(dacl))
                fixed (void* __group_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<byte, byte>.ManagedToUnmanagedIn.GetPinnableReference(group))
                fixed (void* __owner_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<byte, byte>.ManagedToUnmanagedIn.GetPinnableReference(owner))
                fixed (void* __name_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(name))
                {
                    global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                    __retVal = __PInvoke((ushort*)__name_native, objectType, securityInformation, (byte*)__owner_native, (byte*)__group_native, (byte*)__dacl_native, (byte*)__sacl_native);
                    __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                }
 
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "SetNamedSecurityInfoW", ExactSpelling = true, CharSet = global::System.Runtime.InteropServices.CharSet.Unicode)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe uint __PInvoke(ushort* __name_native, uint __objectType_native, uint __securityInformation_native, byte* __owner_native, byte* __group_native, byte* __dacl_native, byte* __sacl_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "GetSecurityDescriptorLength", ExactSpelling = true)]
        internal static extern partial uint GetSecurityDescriptorLength(nint byteArray);
    }
}
internal static partial class Interop
{
    internal static partial class Kernel32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial bool CloseHandle(nint handle)
        {
            unsafe
            {
                int __lastError;
                bool __retVal;
                int __retVal_native;
                {
                    global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                    __retVal_native = __PInvoke(handle);
                    __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                }
 
                // Unmarshal - Convert native data to managed data.
                __retVal = __retVal_native != 0;
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint = "CloseHandle", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke(nint __handle_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial bool OpenThreadToken(nint ThreadHandle, global::System.Security.Principal.TokenAccessLevels dwDesiredAccess, bool bOpenAsSelf, out global::Microsoft.Win32.SafeHandles.SafeTokenHandle phThreadToken)
        {
            unsafe
            {
                int __lastError;
                bool __invokeSucceeded = default;
                phThreadToken = default;
                int __bOpenAsSelf_native = default;
                nint __phThreadToken_native = default;
                bool __retVal = default;
                int __retVal_native = default;
                // Setup - Perform required setup.
                global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller<global::Microsoft.Win32.SafeHandles.SafeTokenHandle>.ManagedToUnmanagedOut __phThreadToken_native__marshaller = new();
                try
                {
                    // Marshal - Convert managed data to native data.
                    __bOpenAsSelf_native = (int)(bOpenAsSelf ? 1 : 0);
                    {
                        global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                        __retVal_native = __PInvoke(ThreadHandle, dwDesiredAccess, __bOpenAsSelf_native, &__phThreadToken_native);
                        __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                    }
 
                    __invokeSucceeded = true;
                    // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception.
                    __phThreadToken_native__marshaller.FromUnmanaged(__phThreadToken_native);
                    // Unmarshal - Convert native data to managed data.
                    __retVal = __retVal_native != 0;
                    phThreadToken = __phThreadToken_native__marshaller.ToManaged();
                }
                finally
                {
                    if (__invokeSucceeded)
                    {
                        // CleanupCalleeAllocated - Perform cleanup of callee allocated resources.
                        __phThreadToken_native__marshaller.Free();
                    }
                }
 
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "OpenThreadToken", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke(nint __ThreadHandle_native, global::System.Security.Principal.TokenAccessLevels __dwDesiredAccess_native, int __bOpenAsSelf_native, nint* __phThreadToken_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial bool OpenProcessToken(nint ProcessToken, global::System.Security.Principal.TokenAccessLevels DesiredAccess, out global::Microsoft.Win32.SafeHandles.SafeTokenHandle TokenHandle)
        {
            unsafe
            {
                int __lastError;
                bool __invokeSucceeded = default;
                TokenHandle = default;
                nint __TokenHandle_native = default;
                bool __retVal = default;
                int __retVal_native = default;
                // Setup - Perform required setup.
                global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller<global::Microsoft.Win32.SafeHandles.SafeTokenHandle>.ManagedToUnmanagedOut __TokenHandle_native__marshaller = new();
                try
                {
                    {
                        global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                        __retVal_native = __PInvoke(ProcessToken, DesiredAccess, &__TokenHandle_native);
                        __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                    }
 
                    __invokeSucceeded = true;
                    // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception.
                    __TokenHandle_native__marshaller.FromUnmanaged(__TokenHandle_native);
                    // Unmarshal - Convert native data to managed data.
                    __retVal = __retVal_native != 0;
                    TokenHandle = __TokenHandle_native__marshaller.ToManaged();
                }
                finally
                {
                    if (__invokeSucceeded)
                    {
                        // CleanupCalleeAllocated - Perform cleanup of callee allocated resources.
                        __TokenHandle_native__marshaller.Free();
                    }
                }
 
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "OpenProcessToken", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke(nint __ProcessToken_native, global::System.Security.Principal.TokenAccessLevels __DesiredAccess_native, nint* __TokenHandle_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Kernel32
    {
        [global::System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint = "GetCurrentProcess", ExactSpelling = true)]
        internal static extern partial nint GetCurrentProcess();
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial bool SetThreadToken(nint ThreadHandle, global::Microsoft.Win32.SafeHandles.SafeTokenHandle hToken)
        {
            unsafe
            {
                int __lastError;
                nint __hToken_native = default;
                bool __retVal = default;
                int __retVal_native = default;
                // Setup - Perform required setup.
                global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller<global::Microsoft.Win32.SafeHandles.SafeTokenHandle>.ManagedToUnmanagedIn __hToken_native__marshaller = new();
                try
                {
                    // Marshal - Convert managed data to native data.
                    __hToken_native__marshaller.FromManaged(hToken);
                    {
                        // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned.
                        __hToken_native = __hToken_native__marshaller.ToUnmanaged();
                        global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                        __retVal_native = __PInvoke(ThreadHandle, __hToken_native);
                        __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                    }
 
                    // Unmarshal - Convert native data to managed data.
                    __retVal = __retVal_native != 0;
                }
                finally
                {
                    // CleanupCallerAllocated - Perform cleanup of caller allocated resources.
                    __hToken_native__marshaller.Free();
                }
 
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "SetThreadToken", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke(nint __ThreadHandle_native, nint __hToken_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Kernel32
    {
        [global::System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint = "GetCurrentThread", ExactSpelling = true)]
        internal static extern partial nint GetCurrentThread();
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static unsafe partial bool AdjustTokenPrivileges(global::Microsoft.Win32.SafeHandles.SafeTokenHandle TokenHandle, bool DisableAllPrivileges, global::Interop.Advapi32.TOKEN_PRIVILEGE* NewState, uint BufferLength, global::Interop.Advapi32.TOKEN_PRIVILEGE* PreviousState, uint* ReturnLength)
        {
            unsafe
            {
                int __lastError;
                nint __TokenHandle_native = default;
                int __DisableAllPrivileges_native = default;
                bool __retVal = default;
                int __retVal_native = default;
                // Setup - Perform required setup.
                global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller<global::Microsoft.Win32.SafeHandles.SafeTokenHandle>.ManagedToUnmanagedIn __TokenHandle_native__marshaller = new();
                try
                {
                    // Marshal - Convert managed data to native data.
                    __DisableAllPrivileges_native = (int)(DisableAllPrivileges ? 1 : 0);
                    __TokenHandle_native__marshaller.FromManaged(TokenHandle);
                    {
                        // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned.
                        __TokenHandle_native = __TokenHandle_native__marshaller.ToUnmanaged();
                        global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                        __retVal_native = __PInvoke(__TokenHandle_native, __DisableAllPrivileges_native, NewState, BufferLength, PreviousState, ReturnLength);
                        __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                    }
 
                    // Unmarshal - Convert native data to managed data.
                    __retVal = __retVal_native != 0;
                }
                finally
                {
                    // CleanupCallerAllocated - Perform cleanup of caller allocated resources.
                    __TokenHandle_native__marshaller.Free();
                }
 
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "AdjustTokenPrivileges", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke(nint __TokenHandle_native, int __DisableAllPrivileges_native, global::Interop.Advapi32.TOKEN_PRIVILEGE* __NewState_native, uint __BufferLength_native, global::Interop.Advapi32.TOKEN_PRIVILEGE* __PreviousState_native, uint* __ReturnLength_native);
            }
        }
    }
}
internal static partial class Interop
{
    internal static partial class Advapi32
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "11.0.14.41101")]
        internal static partial bool DuplicateTokenEx(global::Microsoft.Win32.SafeHandles.SafeTokenHandle ExistingTokenHandle, global::System.Security.Principal.TokenAccessLevels DesiredAccess, nint TokenAttributes, global::Interop.Advapi32.SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, global::System.Security.Principal.TokenType TokenType, ref global::Microsoft.Win32.SafeHandles.SafeTokenHandle DuplicateTokenHandle)
        {
            unsafe
            {
                int __lastError;
                bool __invokeSucceeded = default;
                nint __ExistingTokenHandle_native = default;
                nint __DuplicateTokenHandle_native = default;
                bool __retVal = default;
                int __retVal_native = default;
                // Setup - Perform required setup.
                global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller<global::Microsoft.Win32.SafeHandles.SafeTokenHandle>.ManagedToUnmanagedRef __DuplicateTokenHandle_native__marshaller = new();
                global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller<global::Microsoft.Win32.SafeHandles.SafeTokenHandle>.ManagedToUnmanagedIn __ExistingTokenHandle_native__marshaller = new();
                try
                {
                    // Marshal - Convert managed data to native data.
                    __DuplicateTokenHandle_native__marshaller.FromManaged(DuplicateTokenHandle);
                    __ExistingTokenHandle_native__marshaller.FromManaged(ExistingTokenHandle);
                    {
                        // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned.
                        __DuplicateTokenHandle_native = __DuplicateTokenHandle_native__marshaller.ToUnmanaged();
                        __ExistingTokenHandle_native = __ExistingTokenHandle_native__marshaller.ToUnmanaged();
                        global::System.Runtime.InteropServices.Marshal.SetLastSystemError(0);
                        __retVal_native = __PInvoke(__ExistingTokenHandle_native, DesiredAccess, TokenAttributes, ImpersonationLevel, TokenType, &__DuplicateTokenHandle_native);
                        __lastError = global::System.Runtime.InteropServices.Marshal.GetLastSystemError();
                    }
 
                    // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call.
                    __DuplicateTokenHandle_native__marshaller.OnInvoked();
                    __invokeSucceeded = true;
                    // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception.
                    __DuplicateTokenHandle_native__marshaller.FromUnmanaged(__DuplicateTokenHandle_native);
                    // Unmarshal - Convert native data to managed data.
                    __retVal = __retVal_native != 0;
                }
                finally
                {
                    if (__invokeSucceeded)
                    {
                        // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases.
                        DuplicateTokenHandle = __DuplicateTokenHandle_native__marshaller.ToManagedFinally();
                    }
 
                    // CleanupCallerAllocated - Perform cleanup of caller allocated resources.
                    __DuplicateTokenHandle_native__marshaller.Free();
                    __ExistingTokenHandle_native__marshaller.Free();
                }
 
                global::System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError);
                return __retVal;
                // Local P/Invoke
                [global::System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "DuplicateTokenEx", ExactSpelling = true)]
                [global::System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute((global::System.Runtime.InteropServices.DllImportSearchPath)2048)]
                static extern unsafe int __PInvoke(nint __ExistingTokenHandle_native, global::System.Security.Principal.TokenAccessLevels __DesiredAccess_native, nint __TokenAttributes_native, global::Interop.Advapi32.SECURITY_IMPERSONATION_LEVEL __ImpersonationLevel_native, global::System.Security.Principal.TokenType __TokenType_native, nint* __DuplicateTokenHandle_native);
            }
        }
    }
}