0

I was wondering if there was any way for me to put my .BAT file into my C# Form like here :https://prnt.sc/s1ne88

Is there any way that i can run the BAT from inside the Form

Other Terms : I only want to download the Exe and have the BAT inside the C# form and it run from inside

  • 1
    you can execute a batch file (or any other executable) from a C# program, yes. Pretty sure you can find examples on google already. – ADyson Apr 18 '20 at 08:28
  • You can include the file in your C# program using the .NET embedded resoruce managers. But you cannot run a batch file from memory, which you would have to do, see [this answer](https://stackoverflow.com/a/6243053/653473). You could embed the batch file as text, and then execute it in some other way, for example, by writing it to a temporary file first. – dialer Apr 18 '20 at 08:30
  • you can change the Copy to Output Directory property for the .bat file to be in the same folder as the executable – Slai Apr 18 '20 at 09:51

1 Answers1

3

you can create the bat file from your application using StreamWriter and then run it:

StreamWriter sw = new StreamWriter("file.bat");
sw.WriteLine("ping 8.8.8.8");
sw.Dispose();
System.Diagnostics.Process.Start("file.bat");

OR

you can run the bat commands directly from your application: Documentation

string cmd = "/k ipconfig";
System.Diagnostics.Process.Start("cmd.exe", cmd);
Asad Blum
  • 126
  • 1
  • 6