C# 使用参数启动 EXE 并保存
目前我启动了一个 EXE 文件,所以:
System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo();
processStartInfo.FileName = "Stackoverflow.exe";
processStartInfo.WorkingDirectory = ConfigurationManager.AppSettings["Path"] + name + @"\bin";
System.Diagnostics.Process.Start(processStartInfo);
如果我想添加参数,我会在这里做,对吗?:
System.Diagnostics.Process.Start(processStartInfo, params);
如果没有,在哪里?
另一件事是,我想保存 exe 的参数,它是自动发生还是我必须在打开时设置它?如果是这样,那么我怎样才能实现这一目标?
编辑:
我的意思是保存是.. 我得到了一个带有文本框的表单,从那里你可以启动一个EXE,例如Stackoverflow.exe,在文本框中你可以写:“-hello”,现在下次你打开表单并在表单中选择EXE时,就会有“-hello”仍然写着,这意味着它已经被保存,这就是我想要的
At the moment I start a EXE-File so:
System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo();
processStartInfo.FileName = "Stackoverflow.exe";
processStartInfo.WorkingDirectory = ConfigurationManager.AppSettings["Path"] + name + @"\bin";
System.Diagnostics.Process.Start(processStartInfo);
If i want to add Parameters , I would do it here right?:
System.Diagnostics.Process.Start(processStartInfo, params);
If not, where?
And the other thing is, that I would like to save the params for the exe, does it happen automatically or do I have to set this, while opening? If so, then how I could achieve that?
EDIT:
What I mean with save is..
I got a Form with Textbox, from there u can start a EXE, by example Stackoverflow.exe and in the Textbox u could write: "-hello" , now next time u open the form and select the EXE in the FORM, there is "-hello" still written, that means, it has been saved, thats what I want
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
设置
ProcessStartInfo.Arguments
< /a> 属性。它只是一串以空格分隔的参数。您需要引用任何包含空格等的路径名。这有点痛苦,但这就是这样:(目前还不清楚“保存”参数的含义 - 没有任何东西会记住您上次使用的参数要启动一个流程并下次应用相同的操作,您必须自己执行此操作,这取决于您正在执行的其他操作 - 您可以使用每个用户的设置,例如。与任何其他设置相同的方式。
Set the
ProcessStartInfo.Arguments
property. It's just a string of space-separated arguments. You'll need to quote any path names which include spaces, etc. It's a bit of a pain, but that's what's there :(It's not really clear what you mean by "saving" the parameters - nothing will remember the arguments you last used to start a process and apply the same things next time, no. You'd have to do that yourself. How you do that will depend on what else you're doing - you could use a per-user setting, for example, the same way as any other setting.
您只需将第二个参数中的参数传递给 Process.Start 方法即可。即:
或者您可以使用 ProcessStartInfo。即:
msdn 的类参考
You can simply pass arguments in the second argument to the Process.Start method. Ie:
Alternatively you can use ProcessStartInfo. I.e:
There are some other useful examples in msdn's class reference
您可以在
processStartInfo.Arguments
中设置参数。我不知道你保存它们是什么意思,但它不会做任何事情,因为它只是一个字符串。你可以自己用这个字符串做任何你想做的事情。
You would set arguments in
processStartInfo.Arguments
.I don't know what you mean by saving them, but it won't do anything as it's just a string. You can do whatever you want with this string yourself.
您还可以使用 Arguments 属性
ProcessStartInfo
类。另外,参数不会被保存,为什么要保存呢?如果您在桌面上创建快捷方式,那么这些参数将存储在那里,并且将使用存储的参数调用您的可执行文件,但这与您的应用程序无关。
You could also use the Arguments property in your
ProcessStartInfo
class.Also, the arguments will not be saved and why should they? If you create a shortcut on your desktop, then these arguments are stored there and your executable will be called with the stored arguments, but that has nothing to do with your application.