在C#中打开一个进程 [英] Open a process in C#

查看:173
本文介绍了在C#中打开一个进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在c#

中打开一个exe文件我使用这个命令:System.Diagnostics.Process.Start(notepad.exe);

notepad.exe在我的exe文件附近。

我的程序启动和关闭没有任何错误消息,但它没有打开notepad.exe

可能是什么问题?

谢谢。

I would like to open an exe file in c#
I use this command: System.Diagnostics.Process.Start("notepad.exe");
The notepad.exe is near my exe file.
My program starts and closes without any error message, but it does not open the notepad.exe
What can be the problem?
Thank you.

推荐答案

最可能的原因是系统找不到notepad.exe文件(或者一个它依赖的程序集):它在我的系统上工作正常 - 正如我预期的那样 - 所以你可能正在尝试运行自定义记事本文件(并且你的评论notepad.exe就在我的exe附近文件。会支持它。



因此,如果应用程序与启动EXE文件位于同一文件夹中,则绝对指定路径:

The most likely reason is that the system can't find the "notepad.exe" file (or one of the assemblies it relies upon): it worked fine on my system - as I expected it would - so it's probable that you are trying to run a "custom" notepad file (and your comment that "The notepad.exe is near my exe file." would back that up).

So, if the application is in the same folder as your startup EXE file, then specify the path absolutely:
string p = Application.StartupPath + "\\" + "notepad.exe";
System.Diagnostics.Process.Start(p);

它应该工作 - 假设你的notepad.exe不需要任何其他也不在同一个文件夹中的程序集。

And it should work - assuming your "notepad.exe" doesn't need any other assemblies which aren't also in the same folder.


假设notepad是默认文本程序, Process.Start(@c:\ myfile.txt)将打开带有默认程序的文件。
Assuming notepad is the default text program, Process.Start(@"c:\myfile.txt") will open the file with the default program.


这篇关于在C#中打开一个进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆