P
P
Pavel2014-12-09 23:54:42
Programming
Pavel, 2014-12-09 23:54:42

How can I get data from standard cmd.exe commands in my C# application without calling a subroutine?

Good afternoon!
I want to write a small application for visualizing data received using cmd.exe commands (ping, tracert, netsh, etc.) in C# windows form.
The matter is that all commands are programs (ping.exe, etc) in system32. And you can call and communicate with them using the Process class. But the goal is not to resort to running cmd programs, but to use their features (packet tracing, etc.).
I tried to use reflection, but the programs do not have build protocols. Are there any solutions?
If not, what is needed for your own implementation of these functions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mayorovp, 2014-12-10
@ProgramCodePav

You're confused... First, "subroutine" is a C# synonym for a method. If you're using winforms, then you're already using a bunch of routines :) And what you want to avoid is called "external program" or "child process".
Secondly, reflection is possible only in relation to programs on the .NET platform - and the programs you listed are native. Of course, reflection on them is impossible. For the same reason, it is useless to decompile from - anyway, you will need to write the same thing in another language.
Thirdly, ping, tracert and netsh are not cmd.exe commands. The cmd.exe commands are echo, if, call, set, goto, for, etc., and what you listed are system utilities.
Now for the question.
ping.msdn.microsoft.com/en-us/library/system.net.networ... Never worked with it, but looks handy.
tracert. Use the same class by specifying Ttl in PingOptions.
netsh. Everything is more complicated here. The fact is that this program is a wrapper for a bunch of different settings located in completely different places. If you need to get data, then try searching for it in msdn.microsoft.com/en-us/library/system.net.networ... If it's not there, google it. The main thing is to google without the netsh keyword.
etc. And here everything is not just difficult, but impossible. It is impossible to take a utility unknown in advance and do the same thing that it does without running it at the same time. Therefore, you need to decide - either your program can perform a fixed list of actions - or you can pass any command to it, but it will start child processes. An intermediate option is also possible - there are actions that the program can perform itself, and child processes will be launched to perform others.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question