Antworten:
using System.Diagnostics;
class Program
{
static void Main()
{
Process.Start("C:\\");
}
}
Wenn Ihre Anwendung cmd-Argumente benötigt, verwenden Sie Folgendes:
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.
}
}
}
Schauen Sie sich Process.Start und Process.StartInfo an
Beispiel:
System.Diagnostics.Process.Start("mspaint.exe");
Code kompilieren
Kopieren Sie den Code und fügen Sie ihn in die Main- Methode einer Konsolenanwendung ein. Ersetzen Sie "mspaint.exe" durch den Pfad zu der Anwendung, die Sie ausführen möchten.
Process.Start()
Ich weiß, dass dies gut beantwortet ist, aber wenn Sie interessiert sind, habe ich eine Bibliothek geschrieben, die das Ausführen von Befehlen viel einfacher macht.
Überprüfen Sie es hier: https://github.com/twitchax/Sheller .
startInfo.UseShellExecute = falsewar eine tolle Sache ... Es hat bei mir wie ein Zauber funktioniert! Danke dir! :)