473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

get the return value executed in dos command

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

example:

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

tnx a lot.
Oct 26 '07 #1
10 23881
Killer42
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
jamesd0142
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...
  2.  
  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.,
example:
open the batch file in vb then
changes its content then save
and run the batch file.,

Thanks.
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"
  2.  
  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

tnx
Oct 30 '07 #6
Killer42
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:
Set COMSPEC=C:\WINDOWS\COMMAND.COM
Oct 30 '07 #9
Killer42
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.

Cheers,
Sasi A
Mar 5 '09 #11

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

Similar topics

3
by: Vipul Pathak | last post by:
Hello Friends ! I have the Following Code, that Executes a Stored Procedure and Attempt to read a Returned Integer Value from the StoredProc. But It gives Error ... ADODB.Command (0x800A0BB9)...
2
by: Sara Shoemaker | last post by:
Hi all - I am trying to launch a web browser from within my code for Linux. The problem is that I am getting no failure code back when the browser doesn't launch. (I'm trying to force a failure...
2
by: Sam | last post by:
In our C++ program, we are using the system call to execute another C++ program synchronously. The program executed by system runs without error and returns back a 0. Under conditions we cannot...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
5
by: hans.bonefaas | last post by:
Hi all, I hope someone can help me with the following problem in ASP.net. I want to edit the information for a record in a database (MS Access). On the page I placed several textboxes and...
8
by: Andrew Robinson | last post by:
Are these two equivalent? Is one better than the other? I tend to go with #1 but started wondering.... Thanks, 1: using (SqlConnection cn = new SqlConnection(DataConnection)) using...
4
by: arnuld | last post by:
1.) we usually say /return 0/ indicates success e.g #include <iostream> int main() { int i=3; std::cout << i << std::endl; return 0;
2
by: Steven | last post by:
Hello, In English version of Windows Vista, run a command (for example icacls.exe) as administrator from Command Prompt, i can determine if the command successfully executed base on the return...
4
by: Jeff | last post by:
Hey ..NET 2.0 I have a stored procedure which calculates a value and return that value. I'm wondering if I should use ExecuteNonQuery, ExecuteScalar or ExecuteReader on this stored...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.