Exemplo n.º 1
0
        // Loads the user's profile
        // Note: Beware of Paged Pool memory leaks!!! Unload the user profile when destroying the prison.
        // For each load called there must be a corresponding unload called (independent to process space).
        public void LoadUserProfile()
        {
            Native.NativeMethods.PROFILEINFO profileInfo = new Native.NativeMethods.PROFILEINFO();
            profileInfo.dwSize     = Marshal.SizeOf(profileInfo);
            profileInfo.lpUserName = this.prisonUser.UserName;

            // PI_NOUI 0x00000001 // Prevents displaying of messages
            profileInfo.dwFlags = 0x1;

            profileInfo.lpProfilePath = null;
            profileInfo.lpDefaultPath = null;
            profileInfo.lpPolicyPath  = null;
            profileInfo.lpServerName  = null;

            bool loadSuccess = NativeMethods.LoadUserProfile(this.prisonUser.LogonToken.DangerousGetHandle(), ref profileInfo);
            int  lastError   = Marshal.GetLastWin32Error();

            if (!loadSuccess)
            {
                Logger.Error("Load user profile failed with error code: {0} for prison user {1}", lastError, this.prisonUser.UserName);
                throw new Win32Exception(lastError);
            }

            if (profileInfo.hProfile == IntPtr.Zero)
            {
                Logger.Error("Load user profile failed. HKCU handle was not loaded. Error code: {0} for prison user {1}", lastError, this.prisonUser.UserName);
                throw new Win32Exception(lastError);
            }
        }
        // Loads the user's profile
        // Note: Beware of Paged Pool memory leaks!!! Unload the user profile when destroying the prison.
        // For each load called there must be a corresponding unload called (independent to process space).
        public void LoadUserProfile()
        {
            Native.NativeMethods.PROFILEINFO profileInfo = new Native.NativeMethods.PROFILEINFO();
            profileInfo.dwSize = Marshal.SizeOf(profileInfo);
            profileInfo.lpUserName = this.prisonUser.UserName;

            // PI_NOUI 0x00000001 // Prevents displaying of messages
            profileInfo.dwFlags = 0x1;

            profileInfo.lpProfilePath = null;
            profileInfo.lpDefaultPath = null;
            profileInfo.lpPolicyPath = null;
            profileInfo.lpServerName = null;

            bool loadSuccess = NativeMethods.LoadUserProfile(this.prisonUser.LogonToken.DangerousGetHandle(), ref profileInfo);
            int lastError = Marshal.GetLastWin32Error();

            if (!loadSuccess)
            {
                Logger.Error("Load user profile failed with error code: {0} for prison user {1}", lastError, this.prisonUser.UserName);
                throw new Win32Exception(lastError);
            }

            if (profileInfo.hProfile == IntPtr.Zero)
            {
                Logger.Error("Load user profile failed. HKCU handle was not loaded. Error code: {0} for prison user {1}", lastError, this.prisonUser.UserName);
                throw new Win32Exception(lastError);
            }
        }