dos command

Posted on 1998-11-19
Last Modified: 2010-05-03
can i write a program in vb to execute dos command ?
Question by:qwertyuiopasdfghjkl

Accepted Solution

tward earned 30 total points
ID: 1445603
Check out the Shell Command or the ShellExecute API call.

Expert Comment

ID: 1445604
MyApp shell("C:\Windows\" , 1)
AppActivate MyApp

Expert Comment

ID: 1445605
Here is a complete answer:

' this part in your general decleration
'------- start here  ------------

option Explicit
                  Dim ret3&
                  Private Declare Function ShellExecute Lib "shell32.dll" Alias _
                      "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
                       String, ByVal lpFile As String, ByVal lpParameters As String, _
                      ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
                    ' or visit the home page

'------ end general decleration --------

'place this code in your form

'--------- code start here -------

Private Sub cmdRunCalculator_Click()
                  ' Run any program EXE,COM from here.
                  ret3& = ShellExecute(Me.hwnd, "Open", "calc.exe", "", App.Path, 1)
                  End Sub

'--- code end here ---

if you need more help get the complete source code and sample from:


Author Comment

ID: 1445606
then how to capture the result return from ms-dos ? and send the command again ?

Expert Comment

ID: 1445607

make the result a file.

try this:

c:\dir > my-dir.txt

now look at the file my-dir.txt with notepad.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity 2008 2 56
Excel object stays open 19 71
Put text in a picture ASP.NET C# 2 50
Help with retrieving partial value from a column using VB.NET 4 44
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now