简体   繁体   English

以 C# 形式运行批处理文件

[英]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我想知道是否有任何方法可以将 my.BAT 文件放入我的 C# 表格中,如下所示: https://prnt.sc/s1ne88

Is there any way that i can run the BAT from inside the Form有什么方法可以从表单内部运行 BAT

Other Terms: I only want to download the Exe and have the BAT inside the C# form and it run from inside其他条款:我只想下载 Exe 并将 BAT 放在 C# 表单中,它从内部运行

you can create the bat file from your application using StreamWriter and then run it:您可以使用 StreamWriter 从您的应用程序创建 bat 文件,然后运行它:

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您可以直接从您的应用程序运行 bat 命令: 文档

string cmd = "/k ipconfig";
System.Diagnostics.Process.Start("cmd.exe", cmd);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM