Zenith0628
Zenith0628

Reputation: 1

Running a Batch file in C# Form

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

Upvotes: 0

Views: 3000

Answers (1)

Asad Blum
Asad Blum

Reputation: 126

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

Upvotes: 3

Related Questions