コード例 #1
0
ファイル: TokenHandle.cs プロジェクト: tdctaz/NativeWindows
 public static extern bool LoadUserProfile(TokenHandle token, ref ProfileInfo profileInfo);
コード例 #2
0
 public static extern bool LoadUserProfile(TokenHandle token, ref ProfileInfo profileInfo);
コード例 #3
0
ファイル: TokenHandle.cs プロジェクト: tdctaz/NativeWindows
 public void UnloadUserProfile(ref ProfileInfo profileInfo)
 {
     if (!NativeMethods.UnloadUserProfile(this, profileInfo.Profile))
     {
         ErrorHelper.ThrowCustomWin32Exception();
     }
 }
コード例 #4
0
ファイル: Token.cs プロジェクト: tdctaz/NativeWindows
 public void UnloadUserProfile(ref ProfileInfo profileInfo)
 {
     _handle.UnloadUserProfile(ref profileInfo);
 }
コード例 #5
0
ファイル: Token.cs プロジェクト: tdctaz/NativeWindows
 public void LoadUserProfile(ref ProfileInfo profileInfo)
 {
     _handle.LoadUserProfile(ref profileInfo);
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: tdctaz/NativeWindows
        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);
 }