Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

dos command

can i write a program in vb to execute dos command ?
0
qwertyuiopasdfghjkl
Asked:
qwertyuiopasdfghjkl
1 Solution
 
twardCommented:
Check out the Shell Command or the ShellExecute API call.
0
 
cameron2Commented:
MyApp shell("C:\Windows\Command.com" , 1)
AppActivate MyApp
0
 
a111a111a111Commented:
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
                    ' shayplace@hotmail.com or visit the home page  http://www.hili.com/~shay

'------ 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: http://www.hili.com/~shay/link/vbexamples.htm



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

make the result a file.

try this:

c:\dir > my-dir.txt

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


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now