0

I am creating a batch file to remove virtual com ports created before using com0com. at the time of creation, the port names where renamed for example:

change CNCA2 portname=COM20

So when i want to remove i should use the original name like:

remove 2 

which corresponds to the original portname CNCA2

So, what i m trying to do here is if the user chooses to remove Port COM20, how can get the original name which is CNCxx ?

below is the sample of command i used:enter image description here

as u can see, when i write remove COM150 there is no change, so i need to get the corresponding name which is remove 2.

so from the c# application how can i get the corresponding name without manually using a list command?

Thanks.

Liban
  • 641
  • 5
  • 19
  • 32

1 Answers1

2

You could spawn a command prompt process that runs the list command and capture the output by redirecting stdout to a text file. Then read the results back from the file.

From the example above, it should be relatively simple to parse the results and use them to create a Dictionary, so you can then easily look up the original name given the new name.

Tim Long
  • 13,508
  • 19
  • 79
  • 147
  • yeah thanks for the suggestion. i managed to save the output of the `list` into a text file. i will try to read it back or make a dictionary. although i ve never a dictionary before. – Liban Dec 13 '12 at 04:03
  • You don't need to redirect the output to a file. In .NET the Process class can help you capture the standard output to a stream so you can read it directly. – Alvin Wong Dec 14 '12 at 04:58
  • @AlvinWong, i didnt know the Process class can capture the standard output, that would be much helpful, let me check it how. – Liban Dec 14 '12 at 07:07