PDA

Click to See Complete Forum and Search --> : Retrieving IPCONFIG into ListBox


snufse
Aug 14th, 2007, 11:46 AM
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

Hack
Aug 14th, 2007, 12:21 PM
Does "C:\ipconfig.txt" exist?

DigiRev
Aug 14th, 2007, 06:44 PM
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/ShowCode.asp?txtCodeId=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 >

Al42
Aug 21st, 2007, 11:24 AM
>> appends, > creates a new file.

DigiRev
Aug 21st, 2007, 11:33 PM
>> appends, > creates a new file.

Ah, ok. Never tried that before. :)