Retrieving IPCONFIG into ListBox
I trying to retrieve IPCONFIG data into a ListBox using vb.net. The only code I have found that will do that is as per below. However, the code does not work. Is there a good way to do this?
Dim i As Integer
Dim Shell = CreateObject("Wscript.Shell")
Shell.run("cmd /c ipconfig /all >> C:\ipconfig.txt")
Dim sr As New IO.StreamReader("C:\ipconfig.txt")
Dim s As String = sr.ReadToEnd
For i = 0 To sr.ReadToEnd.LastIndexOf(i)
ListBox1.Items.Add(s(i).ToString)
Next
Re: Retrieving IPCONFIG into ListBox
Does "C:\ipconfig.txt" exist?
Re: Retrieving IPCONFIG into ListBox
It does if you use the > sign after the command, ie:
cmd ipconfig > C:\output.txt
But there will be a delay from when calling the shell statement to when the file is created and written to. This is why doing it like this isn't really the best way.
This is a good example of how to do it:
http://www.pscode.com/vb/scripts/Sho...61262&lngWId=1
It's VB 6 code though. Since, I think it's a small project, you might be able to have VB.NET convert it pretty easily (just open the .vbp file). Then fix whatever few errors there might be.
Edit: It looks like you have 2 >>, try changing it to one >
Re: Retrieving IPCONFIG into ListBox
>> appends, > creates a new file.
Re: Retrieving IPCONFIG into ListBox
Quote:
Originally Posted by Al42
>> appends, > creates a new file.
Ah, ok. Never tried that before. :)