Пример #1
0
 public static extern bool LoadUserProfile(TokenHandle token, ref ProfileInfo profileInfo);
Пример #2
0
 public static extern bool LoadUserProfile(TokenHandle token, ref ProfileInfo profileInfo);
Пример #3
0
 public void UnloadUserProfile(ref ProfileInfo profileInfo)
 {
     if (!NativeMethods.UnloadUserProfile(this, profileInfo.Profile))
     {
         ErrorHelper.ThrowCustomWin32Exception();
     }
 }
Пример #4
0
 public void UnloadUserProfile(ref ProfileInfo profileInfo)
 {
     _handle.UnloadUserProfile(ref profileInfo);
 }
Пример #5
0
 public void LoadUserProfile(ref ProfileInfo profileInfo)
 {
     _handle.LoadUserProfile(ref profileInfo);
 }
Пример #6
0
        public static void Main(string[] args)
        {
            var tokenFactory = new TokenFactory();
            var environmentBlockFactory = new EnvironmentBlockFactory();
            var processFactory = new ProcessFactory();

            const string username = "******";
            const string password = "******";

            GetOrCreateUser(username, password);

            using (var token = tokenFactory.Logon(username, ".", GetSecureString(password)))
            {
                using (var environmentBlockHandle = environmentBlockFactory.Create(token, false))
                {
                    var profileInfo = new ProfileInfo
                    {
                        Size = Marshal.SizeOf(typeof(ProfileInfo)),
                        Username = username,
                        DefaultPath = null,
                    };
                    token.LoadUserProfile(ref profileInfo);

                    IProcessInformation processInformation;
                    var processStartInfo = new ProcessStartInfo
                    {
                        Desktop = string.Empty,
                    };
                    string commandLine = string.Format("\"{0}\"", typeof(TestProgramWhileTrue.Program).Assembly.Location);

                    if (Environment.UserInteractive)
                    {
                        processInformation = processFactory.CreateWithLogin(username, "", password,
                            ProcessLogonFlags.None,
                            null,
                            commandLine,
                            ProcessCreationFlags.NewConsole | ProcessCreationFlags.UnicodeEnvironment,
                            environmentBlockHandle,
                            Environment.CurrentDirectory,
                            processStartInfo);
                    }
                    else
                    {
                        processInformation = processFactory.CreateAsUser(token,
                            null,
                            commandLine,
                            false,
                            ProcessCreationFlags.NewConsole | ProcessCreationFlags.UnicodeEnvironment,
                            environmentBlockHandle,
                            Environment.CurrentDirectory,
                            processStartInfo);
                    }

                    using (processInformation)
                    {
                        Console.WriteLine("Press any key to kill");
                        Console.ReadKey(intercept: true);
                        processInformation.Process.Terminate(0);

                        token.UnloadUserProfile(ref profileInfo);
                        token.DeleteUserProfile();
                        DeleteUser(username);
                    }
                }
            }
        }
Пример #7
0
 public void UnloadUserProfile(ref ProfileInfo profileInfo)
 {
     _handle.UnloadUserProfile(ref profileInfo);
 }
Пример #8
0
 public void LoadUserProfile(ref ProfileInfo profileInfo)
 {
     _handle.LoadUserProfile(ref profileInfo);
 }