PDA

View Full Version : Halp! Vb Refresher



Kalub
August 13th, 2009, 08:11 PM
Hey, can anyone help me with some quick VB code.


Scenario:
User clicks button, cmd starts and shows ipconfig.


How the hell do I do that? I tried this:

Shell("cmd.exe ipconfig")

Import System.Diagnostics.Process
Start("cmd.exe", "ipconfig")




Basically I need to call cmd and pass ipconfig to it, or call ipconfig and somehow pause it so it doesn't just immediately close.


Thanks

Cojafoji
August 13th, 2009, 08:36 PM
just make a batch file

@echo off
ipconfig/all
pause

i'm sorry if you're trying to code an actual executable for some other reason, i guess i wasn't really paying attention.

tl;dr; sorry.

Rob Oplawar
August 13th, 2009, 09:24 PM
Here is a refresher: Visual Basic sucks. Don't use it. Use C# or something.

Kalub
August 13th, 2009, 10:11 PM
I would use C#, but I only have VB Express on this machine, and two I don't really like it.


I know how to do it other ways, but I'm specifically taked with making something, a toolbox so to say, that when you click, "Show me my IP" that's what it does.


I can call ipconfig, but it just closes immediatly. I can call cmd, but I can't pass anything to it. I dunno what to do.

Bastinka
August 13th, 2009, 11:17 PM
http://uk.answers.yahoo.com/question/index?qid=20070611031805AAN6iLI

:google:

Kalub
August 13th, 2009, 11:48 PM
I can't seem to get that page to load, could you possibly quote it for me? And I did google, but with programming I find there are multiple ways to word something, and each has it's own results.

Bastinka
August 13th, 2009, 11:49 PM
Very true, but googling usually results in what you need to write your own interpretation of something unknown.

Because of the way routers and NAT (network address translation) works the only way I know of it to send a request to a web server and get the web server to return the information.

This code should work for you:

System.Net.WebClient myWebClient = new System.Net.WebClient()

System.IO.Stream myStream = myWebClient.OpenRead("http://www.geekped…

System.IO.StreamReader myStreamReader = new System.IO.StreamReader(myStream)

string myIP = myStreamReader.ReadToEnd()

MessageBox.Show(myIP)

However I wouldn't suggest using the URL provided in a live application as it is liable to change. If you want this enabled for an app you will need to setup your own version of IP.php on a webserver.

If you are going to be using this on a specific router (and no others) then you could research your router to see if it has an API or web based interface which you could utilise.
Source(s):

http://www.geekpedia.com/tutorial149_Get… (http://www.geekpedia.com/tutorial149_Get-the-IP-address-in-a-Windows-application.html)

Kalub
August 13th, 2009, 11:59 PM
Nah, that's not what I'm lookin' for bud. More or less I need to find a way to call a command line application (ipconfig) and then keep it open.

Here, open your run command and type "ipconfig" and hit enter. See that? See how it started the program, but since the program was technically over it ended itself before you could read it.

Now open another run prompt and type "cmd" once command prompt is open type "ipconfig" and hit enter. This is what I'm trying to display.



So I need to figure out how to call either ipconfig and keep it from terminating itself, or call cmd and pass ipconfig to it somehow. I just can't figure out how.

Rob Oplawar
August 14th, 2009, 12:53 PM
You don't want to do either of those things. What you want to do is call ipconfig and capture its stdout. You can then display that output stream any way you like.

Kalub
August 14th, 2009, 01:56 PM
I'm actually pretty sure I want to do it that way. I don't want to have to do any more work than I have to. I would rather just have the command prompt do the work.