C# – Run Application

email me

These are two ways to use the Process class to launch an EXE. Both were tested in Visual Studio 2017.

Simplest usage—just launch an EXE.

using System.Diagnostics;

class Program
{
static void Main()
{
// Add your app name here
Process.Start(@"C:\Windows\system32\notepad.exe");
}
}

 

Intermediate usage—launch an EXE with credentials using SecureString

using System.Diagnostics;
using System.Security;

class Program
{
static void Main(string[] args)
{

SecureString strPassword = new SecureString();
// password by character
// it is important to use AppendChar
strPassword.AppendChar('P');
strPassword.AppendChar('a');
strPassword.AppendChar('s');
strPassword.AppendChar('s');
strPassword.AppendChar('w');
strPassword.AppendChar('o');
strPassword.AppendChar('r');
strPassword.AppendChar('d');

Process objProcess = new Process();
objProcess.StartInfo.LoadUserProfile = false;
objProcess.StartInfo.UseShellExecute = false;
objProcess.StartInfo.CreateNoWindow = false;

// enter the app path here
objProcess.StartInfo.WorkingDirectory = @"C:\Windows\system32";

// enter the app name here
objProcess.StartInfo.FileName = "notepad.exe";

// domain name
objProcess.StartInfo.Domain = ".";

// user account
objProcess.StartInfo.UserName = "administrator";
objProcess.StartInfo.Password = strPassword;
objProcess.Start();

}
}

 

Notes

Process Class  SecureString  AppendChar

Inheritance: Object  > MarshalByRefObject  > Component  > Process