Beispiel #1
0
        private static AutoDisposeHandle CreateEnvironmentBlock(IntPtr userToken)
        {
            IntPtr handle;

            if (NativeMethods.CreateEnvironmentBlock(out handle, userToken, false))
            {
                return(AutoDisposeHandle.Create(handle, h => NativeMethods.DestroyEnvironmentBlock(h)));
            }
            return(null);
        }
Beispiel #2
0
        private static AutoDisposeHandle OpenProcessToken(IntPtr processHandle)
        {
            IntPtr handle;

            if (NativeMethods.OpenProcessToken(processHandle, (uint)TokenAccessLevels.MaximumAllowed, out handle))
            {
                return(AutoDisposeHandle.Create(handle, h => NativeMethods.CloseHandle(h)));
            }
            return(null);
        }
Beispiel #3
0
        private static AutoDisposeHandle DuplicateTokenEx(IntPtr originalToken)
        {
            IntPtr handle;

            if (NativeMethods.DuplicateTokenEx(originalToken, (uint)TokenAccessLevels.MaximumAllowed, IntPtr.Zero, NativeMethods.SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, NativeMethods.TOKEN_TYPE.TokenPrimary, out handle))
            {
                return(AutoDisposeHandle.Create(handle, h => NativeMethods.CloseHandle(h)));
            }
            return(null);
        }
Beispiel #4
0
 private static AutoDisposeHandle OpenProcess(int templateProcessId)
 {
     return(AutoDisposeHandle.Create(NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.All, false, templateProcessId), h => NativeMethods.CloseHandle(h)));
 }