Mega Code Archive

 
Categories / C# Tutorial / Windows
 

Start Notepad as the specified user

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);             }         }     } }