Câu trả lời:
using System.Diagnostics;
class Program
{
static void Main()
{
Process.Start("C:\\");
}
}
Nếu ứng dụng của bạn cần đối số cmd, hãy sử dụng một cái gì đó như thế này:
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.
}
}
}
Nhìn vào Process.Start và Process.StartInfo
Thí dụ:
System.Diagnostics.Process.Start("mspaint.exe");
Biên soạn mã
Sao chép mã và dán nó vào phương thức Main của ứng dụng console. Thay thế "mspaint.exe" bằng đường dẫn đến ứng dụng bạn muốn chạy.
Process.Start()
Tôi biết điều này đã được trả lời tốt, nhưng nếu bạn quan tâm, tôi đã viết một thư viện giúp việc thực thi các lệnh dễ dàng hơn nhiều.
Kiểm tra nó ở đây: https://github.com/twitchax/Sheller .
startInfo.UseShellExecute = false
là một điều tuyệt vời ... Nó làm việc cho tôi như một cơ duyên! Cảm ơn bạn! :)