コード例 #1
0
        public static void SetTokenInt(TokenHandle hToken, TOKEN_INFORMATION_CLASS infoClass, int value)
        {
            bool result = SetTokenInformation(hToken, infoClass, ref value, 4);

            if (!result)
            {
                throw new Win32Exception();
            }
        }
コード例 #2
0
 public static extern bool CreateProcessAsUser(
     TokenHandle hToken,
     string lpApplicationName,
     string lpCommandLine,
     IntPtr lpProcessAttributes,
     IntPtr lpThreadAttributes,
     bool bInheritHandles,
     CreateProcessFlags dwCreationFlags,
     IntPtr lpEnvironment,
     string lpCurrentDirectory,
     ref STARTUPINFO lpStartupInfo,
     out PROCESS_INFORMATION lpProcessInformation);
コード例 #3
0
        public static TokenHandle DuplicateTokenEx(TokenHandle hExistingToken, TokenAccess desiredAccess,
                                                   SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType)
        {
            TokenHandle ret;
            bool        result = DuplicateTokenEx(hExistingToken, (uint)desiredAccess, IntPtr.Zero, ImpersonationLevel, TokenType, out ret);

            if (!result)
            {
                throw new Win32Exception();
            }
            return(ret);
        }
コード例 #4
0
        public static int GetTokenInt(TokenHandle hToken, TOKEN_INFORMATION_CLASS infoClass)
        {
            int  size;
            int  value  = 0;
            bool result = GetTokenInformation(hToken, infoClass, ref value, 4, out size);

            if (!result)
            {
                throw new Win32Exception();
            }
            return(value);
        }
コード例 #5
0
        public static bool AdjustTokenPrivileges(TokenHandle hToken, bool disableAllPrivileges, PrivilegeState[] newState)
        {
            int unused;

            LUID_AND_ATTRIBUTES[] newState_conv = ConvertTokenPrivileges(newState);
            bool result = AdjustTokenPrivileges(hToken, disableAllPrivileges, newState_conv, 0, IntPtr.Zero, out unused);

            if (!result)
            {
                throw new Win32Exception();
            }
            return(result);
        }
コード例 #6
0
        public static bool GetTokenElevated(TokenHandle hToken)
        {
            int size;

            TOKEN_ELEVATION te = new TOKEN_ELEVATION();

            te.TokenIsElevated = 0;
            bool result = GetTokenInformation(hToken, TOKEN_INFORMATION_CLASS.TokenElevation, ref te, Marshal.SizeOf(typeof(TOKEN_ELEVATION)), out size);

            if (!result)
            {
                throw new Win32Exception();
            }
            return(te.TokenIsElevated != 0);
        }
コード例 #7
0
        public static TokenHandle GetLinkedToken(TokenHandle hToken)
        {
            int    size;
            IntPtr handle = IntPtr.Zero;
            bool   result = GetTokenInformation(hToken, TOKEN_INFORMATION_CLASS.TokenLinkedToken, ref handle, IntPtr.Size, out size);
            int    err    = Marshal.GetLastWin32Error();

            if (!result)
            {
                // this happens if UAC virtualization is not enabled for the token
                // *that* happens if UAC is disabled for the system, *or* if the user a regular non-admin user.
                if (err == ERROR_NO_SUCH_LOGON_SESSION)
                {
                    return(null);
                }
                throw new Win32Exception(err);
            }
            return(new TokenHandle(handle, true));
        }
コード例 #8
0
 static extern bool AdjustTokenPrivileges(TokenHandle hToken, bool disableAllPrivileges,
                                          [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(TokenPrivilegesMarshaler))]
                                          LUID_AND_ATTRIBUTES[] NewState,
                                          int BufferLength,
                                          IntPtr PreviousState,
                                          out int returnLength);
コード例 #9
0
 public static SECURITY_IMPERSONATION_LEVEL GetTokenImpersonationLevel(TokenHandle hToken)
 {
     return((SECURITY_IMPERSONATION_LEVEL)GetTokenInt(hToken, TOKEN_INFORMATION_CLASS.TokenImpersonationLevel));
 }
コード例 #10
0
 public static TokenType GetTokenType(TokenHandle hToken)
 {
     return((TokenType)GetTokenInt(hToken, TOKEN_INFORMATION_CLASS.TokenType));
 }
コード例 #11
0
 static extern bool SetTokenInformation(TokenHandle TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, [In] ref int TokenInformation, int TokenInformationLength);
コード例 #12
0
 static extern bool GetTokenInformation(TokenHandle TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, ref IntPtr TokenInformation, int TokenInformationLength, out int ReturnLength);
コード例 #13
0
 extern static bool DuplicateTokenEx(SafeHandle hExistingToken, uint dwDesiredAccess,
                                     IntPtr lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out TokenHandle phNewToken);
コード例 #14
0
 static extern bool OpenProcessToken(IntPtr ProcessHandle, int DesiredAccess, out TokenHandle TokenHandle);