Start Notepad as the specified user : Windows Application Process : Windows C# Examples


C# Examples » Windows » Windows Application Process »

 

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




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Windows
» Windows Application Process