Start Notepad as the specified user : Windows Application Process « Windows « C# / CSharp Tutorial






using System;
using System.Security;
using System.Diagnostics;

class MainClass
{
    public static void Main()
    {

        Console.Write("Enter the user's password: ");
        SecureString str = new SecureString();

        str.AppendChar('A');
        str.AppendChar('B');
        str.AppendChar('C');
        str.MakeReadOnly();
        
        ProcessStartInfo startInfo = new ProcessStartInfo();

        startInfo.FileName = "notepad.exe";
        startInfo.UserName = "user";
        //startInfo.Password = "pword";
        startInfo.UseShellExecute = false;

        using (Process process = new Process())
        {
            process.StartInfo = startInfo;
            try
            {
                process.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n\nCould not start Notepad process.");
                Console.WriteLine(ex);
            }
        }
    }
}








29.8.Windows Application Process
29.8.1.Start Notepad as the specified user
29.8.2.Terminating Notepad with CloseMainWindow
29.8.3.Terminating Notepad with Kill
29.8.4.IE processes