To start any application by code, it pretty easy:
static void Main(string[] args)
{
var pi = new ProcessStartInfo
{
FileName = "calc",
//Arguments = "...",
//RedirectStandardOutput = true,
UseShellExecute = false //Allows the redirection of the ouput
};
var p = Process.Start(pi);
}But in that simple case, we could just do:
static void Main(string[] args)
{
var p = Process.Start("calc");
}Sometimes you will need to start an application as the current user, but as the admin as well:
public static void StartApp(string appPath, string parameter, PrivilegeEnum privilege)
{
var psi = new ProcessStartInfo(appPath, parameter);
switch (privilege)
{
case PrivilegeEnum.Admin:
psi.UseShellExecute = true;
psi.Verb = "runas";
break;
case PrivilegeEnum.CurrentUser:
//psi.UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
psi.LoadUserProfile = true;
psi.UseShellExecute = false;
break;
default:
break;
}
var p = new Process();
p.StartInfo = psi;
p.Start();
}
public enum PrivilegeEnum
{
Admin,
CurrentUser
}





