1

I have an exe file which I run through windows command prompt and give command line arguments. 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

I went through this post but it tells on how to execute the exe directly without the running it from 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.

I even tried the following command:

global::ApplicationName.Properties.Resources.MyApplication 

but it gives byte[] and not the path to the application.

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); } } 
2
  • You have an embedded file as a resource in your project? If so you must extract it to a directory in the filsystem before you run it. Commented Oct 20, 2014 at 23:41
  • Yes I have added the application file as a resource. How do I extract it and run it then ? Can i delete it after running it so that the application does not create any temporary junk files ? Commented Oct 20, 2014 at 23:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I tried the following command: byte[] fileContents =global::ApplicationName.Properties.Resources.MyApplication; File.WriteAllBytes("MyApplication.exe", fileContents); MessageBox.Show(MyApplication.exe); but it gives me error
Why are you doing messagebox cloc.exe? The code fragment i have written creates a file in the current directory so you can run it using process.start
I don't want to run the application as it is. i want to run it through command line so i can give it arguments. I did MessageBox.Show to see if it's giving me the path
Ok so use a full path of your choice to extract your executable and then pass the same path to the cmd
I am a beginner to C# could you please explain me how to do that
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.