dos command

can i write a program in vb to execute dos command ?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

twardConnect With a Mentor Commented:
Check out the Shell Command or the ShellExecute API call.
MyApp shell("C:\Windows\" , 1)
AppActivate MyApp
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:

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

make the result a file.

try this:

c:\dir > my-dir.txt

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.