Odpowiedzi:
using System.Diagnostics;
class Program
{
static void Main()
{
Process.Start("C:\\");
}
}
Jeśli twoja aplikacja potrzebuje argumentów cmd, użyj czegoś takiego:
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.
}
}
}
Spójrz na Process.Start i Process.StartInfo
Przykład:
System.Diagnostics.Process.Start("mspaint.exe");
Kompilowanie kodu
Skopiuj kod i wklej go do metody Main aplikacji konsolowej. Zastąp „mspaint.exe” ścieżką do aplikacji, którą chcesz uruchomić.
Process.Start()
Wiem, że odpowiedź jest dobra, ale jeśli jesteś zainteresowany, napisałem bibliotekę, która znacznie ułatwia wykonywanie poleceń.
Sprawdź to tutaj: https://github.com/twitchax/Sheller .
startInfo.UseShellExecute = falseto była niesamowita rzecz ... Działało na mnie jak urok! Dziękuję Ci! :)