469,322 Members | 1,593 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,322 developers. It's quick & easy.

get the return value executed in dos command

how to execute a command in dos in vb 6.,


ping a computer on dos
and then
print the return value on a listbox.,

tnx a lot.
Oct 26 '07 #1
10 23103
8,435 Expert 8TB
Probably depends on what version of VB you're using. But you should be able to use Shell or ShellExecute to run the command, and use a batch file to determine the return code and write it to a file. Then read that file when you get back to your VB code.
Oct 26 '07 #2
469 256MB
Killer has a great idea.

I have been playing about with batch files lately, try:

Expand|Select|Wrap|Line Numbers
  1. REM Pinging...
  3. Ping [ipaddress] > Log.txt
The results will then be output to Log.txt in the directory where your batch file is located.

Now open this file in VB and process the data to find what you require.
<do you know how to create batch files?>
Open Notepad > enter text above > save as > extension .bat not .txt
Oct 26 '07 #3
How to send the default value of ipaddress on the bat., file

Do I need to edit the content of .bat.,
open the batch file in vb then
changes its content then save
and run the batch file.,

Oct 30 '07 #4
Below is a working code which would run from VB or VBA on a Windows machine to execute any DOS command and display the result in a message box. I have used a Ping example, but any other command should work. Batch files are almost obsolete, although the DOS gurus still do a lot with it. The Windows scripting can do a lot more than the batch files.
Expand|Select|Wrap|Line Numbers
  1.     ExecuteDos "Ping sunrisetelecom.com"
  3. Function ExecuteDos(Comm As String)
  4.     Set objShell = CreateObject("WScript.Shell")
  5.     Set objExecObject = objShell.Exec("%comspec% /c " & Comm)
  6.     MsgBox objExecObject.StdOut.ReadAll()
  7. End Function
Oct 30 '07 #5
i got a runtime error when i run the script.,
runtime err: 438
"object doesn't support this property or method"

is there any reference i must include.,
i am using OS 98

Oct 30 '07 #6
8,435 Expert 8TB
Which line produces the error?
Oct 30 '07 #7
Which line produces the error?
the error points to line 5.,
Oct 30 '07 #8
the error points to line 5.,
Sorry xxoulmate...I don't even have a 98 installation around to re-produce the error, I have XP and 2003 servers around me.

Try Putting a set statement in your AutoExec.bat file something like below make sure the path of the Command.com file is correct:
Oct 30 '07 #9
8,435 Expert 8TB
Hm... so from the sound of it, the WScript.Shell object doesn't support the Exec method. Perhaps you have an old version of the scripting runtime. Have you tried Windows Update?
Oct 30 '07 #10
Hi, the above code is working fine. But before executing the command, command prompt is opening for a second and after that only we'r getting the values. Instead of that how to hide the command prompt that is showing for one sec/ upto the result.

Sasi A
Mar 5 '09 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Sara Shoemaker | last post: by
3 posts views Thread by tshad | last post: by
5 posts views Thread by hans.bonefaas | last post: by
8 posts views Thread by Andrew Robinson | last post: by
4 posts views Thread by arnuld | last post: by
4 posts views Thread by Jeff | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.