Пример #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).
        private void LoadUserProfile()
        {
            this.InitializeLogonToken();

            Native.PROFILEINFO profileInfo = new Native.PROFILEINFO();
            profileInfo.dwSize     = Marshal.SizeOf(profileInfo);
            profileInfo.lpUserName = this.user.Username;

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

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

            Boolean loadSuccess = Native.LoadUserProfile(logonToken.DangerousGetHandle(), ref profileInfo);


            if (!loadSuccess)
            {
                Logger.Error("LoadUserProfile failed with error code: {0} for prison {1}", Marshal.GetLastWin32Error(), this.ID);
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            if (profileInfo.hProfile == IntPtr.Zero)
            {
                Logger.Error("LoadUserProfile failed HKCU handle was not loaded. Error code: {0} for prison {1}", Marshal.GetLastWin32Error(), this.ID);
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Пример #2
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).
        private void LoadUserProfile()
        {
            this.InitializeLogonToken();

            Native.PROFILEINFO profileInfo = new Native.PROFILEINFO();
            profileInfo.dwSize = Marshal.SizeOf(profileInfo);
            profileInfo.lpUserName = this.user.Username;

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

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

            Boolean loadSuccess = Native.LoadUserProfile(logonToken.DangerousGetHandle(), ref profileInfo);


            if (!loadSuccess)
            {
                Logger.Error("LoadUserProfile failed with error code: {0} for prison {1}", Marshal.GetLastWin32Error(), this.ID);
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            if (profileInfo.hProfile == IntPtr.Zero)
            {
                Logger.Error("LoadUserProfile failed HKCU handle was not loaded. Error code: {0} for prison {1}", Marshal.GetLastWin32Error(), this.ID);
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }