سؤال

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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

Write the commands to a file and call System.Diagnostics.Process.Start() with the path to the file.

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");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top