C#按下按钮执行另一个程序

Bas*_*987 4 c#

我有一个C#Windows窗体应用程序,但是在按钮上单击我想要执行同一目录中的另一个程序.代码唯一需要做的就是执行另一个程序,仅此而已.

我有以下代码:

using System.Diagnostics;

private void buttonRunScript_Click(object sender, EventArgs e)
{
    System.Diagnostics.ProcessStartInfo start = 
                                    new System.Diagnostics.ProcessStartInfo();
    start.FileName = @"C:\Scripts\XLXS-CSV.exe";
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能正常工作,因为它现在没有做任何事情?在前进中,非常感谢!

Xav*_*jer 14

为什么你使用ProcessStartInfo,你需要一个Process

Process notePad = new Process();    
notePad.StartInfo.FileName   = "notepad.exe";
notePad.StartInfo.Arguments = "ProcessStart.cs"; // if you need some
notePad.Start();
Run Code Online (Sandbox Code Playgroud)

这应该工作;)


Bra*_*one 5

ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\Scripts\XLXS-CSV.exe";
Process.Start(start);
Run Code Online (Sandbox Code Playgroud)


las*_*s88 5

Process yourProcess = new Process();
yourProcess.StartInfo.FileName = @"C:\Scripts\XLXS-CSV.exe";

yourProcess.Start();
Run Code Online (Sandbox Code Playgroud)

您错过了调用 Start 方法和使用 Process 类的机会。:)