Using Shell

rhm54

Member
Joined
Apr 9, 2007
Messages
22
Programming Experience
Beginner
Alright this is a general question but I will use Ping.exe for my example Lets say that I use shell to open ping


Shell("C:\WINDOWS\system32\Ping.exe" & " " & strAddress,
AppWinStyle.NormalFocus, True, 10000)



Where strAddress is some address I want to ping. What I want to know
is how I can capture the output by ping to use in my program.


One more question as well. Why is it that the program will run fine like it is above but if I try %windir%\system32\Ping.exe instead it says it can't find the file?

Thanks in advance.
 
I would use the System.Net.NetworkInformation.Ping class instead.

And Process class instead of legacy Shell function if that were necessary. Don't know about the environment variable, haven't looked into it, but .Net framework have it covered with Environment.GetFolderPath(SpecialFolder).
 
Where strAddress is some address I want to ping. What I want to know
is how I can capture the output by ping to use in my program.


Using SYstem.Diagnostics.Process.Start, as John says, you can get ahold of the output stream the app posts information to, and read from it jsut like any other stream..

One more question as well. Why is it that the program will run fine like it is above but if I try %windir%\system32\Ping.exe instead it says it can't find the file?
Because when you do it in DOS command line, its the DOS command line itself that expands the %windir% variable into c:\windows.. THEN it calls c:\windows\system32\ping.exe

.NET doesnt use DOS to invoke the comamnd so it doesnt expand the variable, so it really thinks youre wanting a path of %windir%....
 
Thanks for the help!

Got one more question. I have just finished a course on Visual basic .NET that was supposed to be comprehensive but I see that it was far from it. I didn't learn anything about the process class or the System.Net.NetworkInformation .Net library. So my question is what is the best reference to push myself from being a beginner to a novice?
 
Thanks for the help!

Got one more question. I have just finished a course on Visual basic .NET that was supposed to be comprehensive but I see that it was far from it. I didn't learn anything about the process class or the System.Net.NetworkInformation .Net library. So my question is what is the best reference to push myself from being a beginner to a novice?

First, press F2, to show the object browser, and just search for NetworkInformation.. It will bring up the name space and its members. Look at them and read the bits of help; this is like the dictionary - you use a dictionary to look up a word, brief bit about it. You cant learn to speak english jsut by reading a dictionary, but when you can speak it, its a handy reference for widening your knowledge.

Then, search for networkinformation walkthrough or networkinformation tutorial and see what google brings...
 
Back
Top