简体   繁体   English

C#如何获取嵌入式.exe文件的PATH

[英]C# How to get the PATH of the embedded .exe file

I have an exe file which I run through windows command prompt and give command line arguments . 我有一个exe文件,可以通过Windows命令提示符运行并提供命令行参数 I went through this post and ran the following command: 我浏览了这篇文章并运行了以下命令:

System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();

But all it did, is to give me resource files located in WindowsFormsApplication1\\obj\\Debug folder 但是它所做的就是为我提供位于WindowsFormsApplication1 \\ obj \\ Debug文件夹中的资源文件

I went through this post but it tells on how to execute the exe directly without the running it from cmd. 我看了这篇文章,但它讲述了如何直接执行exe,而无需从cmd运行它。

I even tried the following command: 我什至尝试了以下命令:

string path = Path.Combine(Path.GetTempPath(), "MyApplication.exe");

It worked but after clearing my C:\\Users\\UserName\\AppData\\Local\\Temp folder the application started giving an error. 它可以工作,但是在清除我的C:\\ Users \\ UserName \\ AppData \\ Local \\ Temp文件夹后,应用程序开始出现错误。

I even tried the following command: 我什至尝试了以下命令:

global::ApplicationName.Properties.Resources.MyApplication

but it gives byte[] and not the path to the application. 但是它给出byte []而不是应用程序的路径。

All I want to know is how to run the application which is embedded in my resources so that I can successfully execute the following command: 我只想知道如何运行嵌入在我的资源中的应用程序,这样我就可以成功执行以下命令:

var proc = new Process
                    {
                        StartInfo = new ProcessStartInfo
                        {
                            FileName = "cmd.exe",
                            Arguments = "/K " + MyApplication+" Argument "+Path1+" "+Path2 ,
                            UseShellExecute = false,
                            RedirectStandardOutput = true,
                            CreateNoWindow = true
                        }
                    };
                    proc.Start();

                    while (!proc.StandardOutput.EndOfStream)
                    {

                        string line = proc.StandardOutput.ReadToEnd();
                        using (System.IO.StreamWriter file = new System.IO.StreamWriter(resultFile))
                        {
                            file.WriteLine(line);
                        }
                    }

Extract the resource into a file in the filesystem and then run it. 将资源提取到文件系统中的文件中,然后运行它。

byte[] fileContents = ApplicationName.Properties.Resources.MyApplication;
File.WriteAllBytes("MyApplication.exe", fileContents);

Now you can run the file using MyApplicaton.exe as path. 现在,您可以使用MyApplicaton.exe作为路径运行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM