|
-
Aug 14th, 2007, 11:46 AM
#1
Thread Starter
Fanatic Member
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
-
Aug 14th, 2007, 12:21 PM
#2
Re: Retrieving IPCONFIG into ListBox
Does "C:\ipconfig.txt" exist?
-
Aug 14th, 2007, 06:44 PM
#3
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 >
-
Aug 21st, 2007, 11:24 AM
#4
Re: Retrieving IPCONFIG into ListBox
>> appends, > creates a new file.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Aug 21st, 2007, 11:33 PM
#5
Re: Retrieving IPCONFIG into ListBox
 Originally Posted by Al42
>> appends, > creates a new file.
Ah, ok. Never tried that before.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|