微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我如何选择一个应用程序以在 c# 中启动进程控件?

如何解决我如何选择一个应用程序以在 c# 中启动进程控件?

我一直在查看其他帖子以了解如何在 c# 中启动应用程序。我正在制作一个应用程序启动器,并添加了过程控制。我写了这段代码

Process.FileName = "myapp.exe";
Process.Start();

我认为这不是确切的代码,但第 1 行是我遇到错误的地方。错误是即使文件在同一目录下也找不到。

我的ide是visual studio 2019,我使用.net framework 4.8和.net core 5

解决方法

看来您需要改用 ProcessStartInfo 类:

using (Process myProcess = new Process())
{
    myProcess.StartInfo.UseShellExecute = false;   
    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
    myProcess.StartInfo.CreateNoWindow = true;
    myProcess.Start();
    // This code assumes the process you are starting will terminate itself.
    // Given that is is started without a window so you cannot terminate it
    // on the desktop,it must terminate itself or you can do it programmatically
    // from this application using the Kill method.
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。