Risposte:
using System.Diagnostics;
class Program
{
static void Main()
{
Process.Start("C:\\");
}
}
Se l'applicazione richiede argomenti cmd, utilizzare qualcosa del genere:
using System.Diagnostics;
class Program
{
static void Main()
{
LaunchCommandLineApp();
}
/// <summary>
/// Launch the application with some options set.
/// </summary>
static void LaunchCommandLineApp()
{
// For the example
const string ex1 = "C:\\";
const string ex2 = "C:\\Dir";
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "dcm2jpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}
}
}
Guarda Process.Start e Process.StartInfo
Esempio:
System.Diagnostics.Process.Start("mspaint.exe");
Compilazione del codice
Copia il codice e incollalo nel metodo principale di un'applicazione console. Sostituire "mspaint.exe" con il percorso dell'applicazione che si desidera eseguire.
Process.Start()
So che questo ha una buona risposta, ma se sei interessato, ho scritto una libreria che semplifica l'esecuzione dei comandi.
Dai un'occhiata qui: https://github.com/twitchax/Sheller .
startInfo.UseShellExecute = falseè stata una cosa fantastica ... Ha funzionato per me come un incantesimo! Grazie! :)