从ASP.NET C#启动一个程序

我有一个程序(我创建),我想在网页加载时在服务器上启动它. 这是我的代码 public partial class _Default : System.Web.UI.Page{ Process app = new Process(); protected void Page_Load(object sender, EventArgs e) { app.St

我有一个程序(我创建),我想在网页加载时在服务器上启动它.

这是我的代码

public partial class _Default : System.Web.UI.Page
{
    Process app = new Process();
    protected void Page_Load(object sender,EventArgs e)
    {
        app.StartInfo.FileName = @"D:/Path to /My/Program to be run.exe";
        app.Start();
    }
}

现在应用程序是“运行”,但是它会立即崩溃.
如果我只是运行应用程序(通过双击exe)它运行,一切都很好.

任何人看到我是否在这里缺少一些东西?

解决方法

您可以使用ProcessStartInfo.

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @"D:/Path to /My/Program to be run.exe";
psi.WorkingDirectory = IO.Path.GetDirectoryName(psi.FileName);
Diagnostics.Process.Start(psi);

作者: dawei

【声明】:滨州站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部