Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In a command prompt I can type "ipconfig" and a list of internet information will appears. I want to do this in a C# console program. Basically, I want to run the C# program and I want to read and store everything that is given in "c:\ipconfig".

"ipconfig" is a String in which that I can set to be anything and "c:\" is the folder directory.

Is it possible to do that in C#? Any information is appreciated.

FYI: This example may be silly but I am working on a problem that is very similar to this and apparently it is the only way to do it. I do not have any API for it.


Edit:

Since everyone is confused of the questions, here is it in more details:

All I do in command prompt is navigate to a specific directly where I installed my application and issuing a commnad and a list of info will show up. I want to capture this info. And, I want to do this all in C# because I then want to process that info into other applications that I made.
Posted
Updated 7-Oct-14 10:27am
v2
Comments
Maciej Los 7-Oct-14 13:41pm    
As far as i know ipconfig gets an information about devices used to connect to internet. .NET framework provides methods to list all devices and its details.
Sergey Alexandrovich Kryukov 7-Oct-14 14:50pm    
Probably, but we don't know what exactly OP wants to get; the question says "a list if internet information", so, using ipconfig could make sense. Please see the solutions 1-3.

If you have the solution based entirely on .NET FCL, it would be useful if you post it, too.

—SA
Jaxam 7-Oct-14 14:15pm    
HiI used ipconfig as an example but the work i am doing is not ipconfig. It is using the same idea in command prompt, however, as i stated in the FYI. There is not API for what I am doing as well.
Maciej Los 7-Oct-14 14:49pm    
Please, use 'Reply' button to post comment as an 'answer' to the other comment.
In other way, the commentator will never see your comment ;)
BillWoodruff 7-Oct-14 14:16pm    
See this for alternative ways using .NET to get the same information ipconfig provides:

http://stackoverflow.com/questions/15184495/parsing-windows-ipconfig-all-output

This application should not be in C:. Do you know that a system does not even have to have drive C?!
And this is not a "DOS command". In modern OS, there is no such thing.

Simply use System.Diagnostics.Process.Start with redirection of StandardOutput:
http://msdn.microsoft.com/en-us/library/0w4h05yb(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput%28v=vs.110%29.aspx[^] (code sample can be found here),
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo(v=vs.110).aspx[^].

—SA
 
Share this answer
 
Comments
[no name] 7-Oct-14 14:56pm    
Ok, my 5. But to be honest I expected to read how to get the Information without using such an ugly method :). Anyway your Explanation of using Process is much more complete.
Regards, Bruno
Sergey Alexandrovich Kryukov 7-Oct-14 14:58pm    
Thank you, Bruno.
Agree. This just answers the question, not giving better alternatives. But, in this case, it might be not that bad.
Maybe Maciej (please see his comment to the question) will do the job. :-)
—SA
Maciej Los 7-Oct-14 15:04pm    
Please, see my answer ;)
BTW: voted 4, because i'm almost sure that there exists better way ;)
Sergey Alexandrovich Kryukov 7-Oct-14 16:28pm    
Maybe; "better" is somewhat "philosophical here". I appreciate that you posted your alternative answer.
See also my comments about not using CMD.EXE. Perhaps you misread my answer a bit.
—SA
Maciej Los 7-Oct-14 16:37pm    
I'm philosophical person, if i can say this way ;)
The book written by Thomas Cathcart and Daniel Clein: "Plato and a Platypus Walk into the Bar" is my personal best!. Polish version, of course. I've got an audiobook readed by the best polish actor (comedian).
I'm looking for english version of book. Unfortunately, inaccessible in Poland ;(
Why to torture yourself by sending some command to the 'command prompt'?
Isn't better to use .net classes, objects?

Please, see:
Network Programming in the .NET Framework[^]
NetworkInterface Class[^]

Quite often used alternative is WMI[^], which provides functionality to get information about any devices connected to the computer.
More: WMI Classes[^]
 
Share this answer
 
v2
Comments
[no name] 7-Oct-14 15:11pm    
+5. That is the good way. Regards, Bruno
Maciej Los 7-Oct-14 15:12pm    
Thank you, Bruno ;)
Sergey Alexandrovich Kryukov 7-Oct-14 16:27pm    
You did it. Good alternative approach, a 5.
—SA
Maciej Los 7-Oct-14 16:28pm    
Thank you, Sergey ;)
Sergey Alexandrovich Kryukov 7-Oct-14 16:31pm    
One big note: nobody talked about "command prompt" (CMD.EXE). Actually, using CMD.EXE is a big mistakes of many. We are talking about starting the process using command line. Big difference. CMD.EXE is not used and should not be used.

[EDIT]

Sorry. Now I see where it comes from: Bruno Sprecher meant using CMD.EXE, but I did not. Please compare out answers and see the difference. Using CMD.EXE is a big mistake.

—SA
My ProcessCommunicator[^] article may give you an idea of how to do that and some of the pitfalls.



I'd also like to point out that maybe the console app that processes the output needn't actually execute the command. You can write a processor app that reads its input from a pipe:

someutility | processor
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 7-Oct-14 14:45pm    
Interesting approach, 5ed.
—SA
Maciej Los 7-Oct-14 14:50pm    
Agree, +5!
You can use the class Process and Redirect Input and Output of cmd.exe.
More or less an easy Thing, simply read the doc in MSDN an Play a Little bit.

BTW 1.) it is not DOS it is as you mentioned also "command prompt".
BTW 2.) There are other/better ways to get the same info.

[EDIT]
Ooooh yes it is Standard- Input/Output. See comment on this answer
[/EDIT]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 7-Oct-14 14:47pm    
Agree, but that's StandardOutput should be redirected (I would also redirect StandardError, just in case).
Input comes in command line only (line in all more or less practical and reasonable command-line applications).
I voted 4, provided a bit more detail in my Solution 3.
—SA
[no name] 7-Oct-14 14:53pm    
Thanks for your comment and your vote. Sorry, sometimes I forget about such "details" and assume it is clear.
Maciej Los 7-Oct-14 14:52pm    
Bruno, can you elaborate second point? Do you thing about WMI queries or something?
[no name] 7-Oct-14 14:59pm    
I mean directly by WIN API one can have the Information. Because doing it with cmd.exe and the command ipconfig depends very much of the OS language which is installed....faced these last week on an chinese System :)

*Lol* just recognized after a comment of Sergey that you recomended something same ;)
Maciej Los 7-Oct-14 15:04pm    
In Poland we often use this sentence: What means experience?!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900