Results 1 to 5 of 5

Thread: Retrieving IPCONFIG into ListBox

  1. #1

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Retrieving IPCONFIG into ListBox

    Does "C:\ipconfig.txt" exist?

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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 >

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Retrieving IPCONFIG into ListBox

    Quote 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
  •  



Click Here to Expand Forum to Full Width