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

3
  • 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. Commented Apr 18, 2020 at 8: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. 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. Commented Apr 18, 2020 at 8:30
  • you can change the Copy to Output Directory property for the .bat file to be in the same folder as the executable Commented Apr 18, 2020 at 9:51

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.