运行在C#code一个EXEcode、EXE

2023-09-02 21:27:39 作者:Angus(愛神)

我在我的C#项目一个exe文件引用。我如何调用该exe文件从我的code?

解决方案

 使用System.Diagnostics程序;
类节目
{
    静态无效的主要()
    {
    //
    //使用的Process.Start这里。
    //
    的Process.Start(C:\);
    }
}
 

如果您的应用程序需要CMD参数,使用这样的:

 使用System.Diagnostics程序;

类节目
{
    静态无效的主要()
    {
    LaunchCommandLineApp();
    }

    ///<总结>
    ///启动了一些选项设置的传统应用程序。
    ///< /总结>
    静态无效LaunchCommandLineApp()
    {
    //对于这个例子
    常量字符串EX1 =C:\;
    常量字符串EX2 =C:\目录;

    //使用的ProcessStartInfo类
    的ProcessStartInfo的StartInfo =新的ProcessStartInfo();
    startInfo.CreateNoWindow = FALSE;
    startInfo.UseShellExecute = FALSE;
    startInfo.FileName =dcm2jpg.exe;
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.Arguments =-fj -o + EX1 +-z 1.0 -sy+ EX2;

    尝试
    {
        //开始与我们指定的信息的过程。
        //调用WaitForExit然后using语句将关闭。
        使用(流程exeProcess =的Process.Start(StartInfo的))
        {
        exeProcess.WaitForExit();
        }
    }
    抓住
    {
        //日志错误。
    }
    }
}
 

哪些文件属于某一vb工程中的文件

I have an exe file reference in my C# project. How do I invoke that exe from my code?

解决方案

using System.Diagnostics;
class Program
{
    static void Main()
    {
    //
    // Use Process.Start here.
    //
    Process.Start("C:\");
    }
}

If your application needs cmd arguments, use something like this:

using System.Diagnostics;

class Program
{
    static void Main()
    {
    LaunchCommandLineApp();
    }

    /// <summary>
    /// Launch the legacy application with some options set.
    /// </summary>
    static void LaunchCommandLineApp()
    {
    // For the example
    const string ex1 = "C:\";
    const string ex2 = "C:\Dir";

    // Use ProcessStartInfo class
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = false;
    startInfo.UseShellExecute = false;
    startInfo.FileName = "dcm2jpg.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.Arguments = "-f j -o "" + ex1 + "" -z 1.0 -s y " + ex2;

    try
    {
        // Start the process with the info we specified.
        // Call WaitForExit and then the using statement will close.
        using (Process exeProcess = Process.Start(startInfo))
        {
        exeProcess.WaitForExit();
        }
    }
    catch
    {
        // Log error.
    }
    }
}

 
精彩推荐
图片推荐