简体   繁体   中英

creating a batch file in c#

This is my first time creating a batch. basically i want write commands in the command Promt. so i need batch file so that i can it in c# and does the task.

The commands looks like this:

install PortName=COM50-
bcdedit.exe -set TESTSIGNING OFF

How i can create the batch file and run it using c# code.

Thanks

Details: i am using com0com to create virtual ports, so the main idea is to automate the process, so i can create port without going to command port and write the commands.

将命令写入文件并使用文件路径调用System.Diagnostics.Process.Start()

You maybe don't need a batch file :-

 Process myprocess = new Process();
 myprocess.StartInfo.FileName = @"C:\WHERE_EVER\bcdedit.exe";
 // I dont know the exact switch, but im sure you would be able to work this out.
 myprocess.StartInfo.Arguments = @"Install PortName=COM50 -set TESTSIGNING OFF";
 myprocess.Start();

System.Diagnostics.Process is your best option.

Provides access to local and remote processes and enables you to start and stop local system processes.

For example;

System.Diagnostics.Process.Start("c:\\yourfilename.bat");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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