C#点击按钮执行另一个程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15948328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# Execute another program on button click
提问by BassieBas1987
I have a C# Windows Form application, but on a button click i want to execute another program that is in the same directory. The only thing that the code needs to do, is to execute another program, nothing more, nothing less.
我有一个 C# Windows 窗体应用程序,但是在单击按钮时,我想执行同一目录中的另一个程序。代码唯一需要做的就是执行另一个程序,仅此而已。
I have the following code:
我有以下代码:
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";
}
How can i make this work properly, because it is not doing anything right now? In forward, many thanks!
我怎样才能使它正常工作,因为它现在没有做任何事情?在前进,非常感谢!
采纳答案by Xavjer
Why are u using a ProcessStartInfo, you need a Process
为什么你使用 ProcessStartInfo,你需要一个 Process
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "ProcessStart.cs"; // if you need some
notePad.Start();
This should work ;)
这应该有效;)
回答by Brandon Boone
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\Scripts\XLXS-CSV.exe";
Process.Start(start);
回答by laszlokiss88
Process yourProcess = new Process();
yourProcess.StartInfo.FileName = @"C:\Scripts\XLXS-CSV.exe";
yourProcess.Start();
You missed to call the Start method and to use the Process class. :)
您错过了调用 Start 方法和使用 Process 类的机会。:)