簡體   English   中英

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

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

我有一個exe文件,可以通過Windows命令提示符運行並提供命令行參數 我瀏覽了這篇文章並運行了以下命令:

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

但是它所做的就是為我提供位於WindowsFormsApplication1 \\ obj \\ Debug文件夾中的資源文件

我看了這篇文章,但它講述了如何直接執行exe,而無需從cmd運行它。

我什至嘗試了以下命令:

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

它可以工作,但是在清除我的C:\\ Users \\ UserName \\ AppData \\ Local \\ Temp文件夾后,應用程序開始出現錯誤。

我什至嘗試了以下命令:

global::ApplicationName.Properties.Resources.MyApplication

但是它給出byte []而不是應用程序的路徑。

我只想知道如何運行嵌入在我的資源中的應用程序,這樣我就可以成功執行以下命令:

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);
                        }
                    }

將資源提取到文件系統中的文件中,然后運行它。

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

現在,您可以使用MyApplicaton.exe作為路徑運行文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM