在C#中执行exe文件 [英] execute an exe file in C#

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

问题描述

如何在C#中执行exe文件?

Process.Start()没用!

解决方案

参见下面的MSDN示例



 使用系统; 
使用 System.Diagnostics;
使用 System.ComponentModel;

命名空间 MyProcessSample
{
class MyProcess
{
public static void Main()
{
处理myProcess = new Process();

try
{
myProcess.StartInfo.UseShellExecute = false < /跨度>;
// 你可以启动任何流程,HelloWorld是一个无用的例子。
myProcess.StartInfo.FileName = C:\\HelloWorld.exe;
myProcess.StartInfo.CreateNoWindow = true ;
myProcess.Start();
// 此代码假定您启动的流程将自行终止。
// 鉴于是在没有窗口的情况下启动,因此无法终止它
// 在桌面上,它必须自行终止,或者您可以通过编程方式执行
// 来自此应用程序使用Kill方法。
}
catch (例外e)
{
Console.WriteLine(e.Message);
}
}
}
}


你的意思是它没用 ??有没有错误信息?描述你的问题。帮助别人帮助你,不要只说它没用或它没有用!



无论如何,有一个看看这里 [ ^ ]



它是 Process.Start()顺便说一下,不是 Process.Star ()(提及以防万一......)。


首先,请看我对这个问题的评论。请遵守。



你是对的,在某种程度上: Process.Start 不是非常很有用,因为在大多数情况下,开发应用程序启动其他进程是一个非常糟糕的主意,因为进程很好地隔离,因此您与这些进程协作的能力非常有限。但是,当你真正需要启动一些应用程序时,这个非常粗略的经验法则有许多排除。



为此,进程。开始不仅有用,而且是唯一的出路。实现这一目标是如此困难,以至于只有那些臭名昭着的几乎所有人都搞砸了。我相信你不是其中之一,所以我无法理解你发言的原因。


祝你好运,

< DD> -SA

how can I execute an exe file in C#?
Process.Start() wasn''t useful!

解决方案

See the below MSDN example

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            Process myProcess = new Process();

            try
            {
                myProcess.StartInfo.UseShellExecute = false;
                // You can start any process, HelloWorld is a do-nothing example.
                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.
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}


What do you mean "it wasn''t useful"?? Any error-message? Describe your problem. Help others to help you, don''t just state "it wasn''t useful" or "it didn''t work"!

Anyway, have a look here[^]

It''s Process.Start() by the way, not Process.Star() (mentioning that just in case...).


First of all, please see my comment to the question. Please comply.

You are right, in a way: Process.Start is not very useful, because in most cases, developing application starting some other process is a pretty bad idea, because processes are well isolated, so your ability to collaborate with those processes are extremely limiting. However, this very rough rule of thumb has many exclusions, when you actually need to start some application.

And for this purpose, Process.Start is not only useful, it''s the only way to go. And achieving this goal is so hard to screw up that only people who notoriously screw up nearly everything can fail. I''m sure you are not one of them, so I cannot understand the reason of your statement.

Good luck,
—SA


这篇关于在C#中执行exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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