Results 1 to 8 of 8

Thread: Running Programs Like DOS

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Posts
    29
    I want to run a program (Not one I made) that only seems to working Dos. I need to run it from my Program. I have tried using ShellExecute, but it doesn't seem to work.

  2. #2
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593
    Try using the Shell command instead, like this:

    Code:
    Shell "C:\MYDIR\MYPROG.EXE"
    The Shell command basically works like a DOS prompt. You could call dir like this:

    Code:
    Shell "DIR *.*"

  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    I don't think I completely understand. But I nearly always use the ShellExecute to call a handful of dos apps and the follow code has always worked for me:

    Code:
    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
    Private Const SW_NORMAL = 1
    
    Private Sub Command1_Click()
    Dim sPrg as string
    'Make sure you enter the full path.
    sPrg="c:\marcbrkr.exe"
    lret = ShellExecute(0&, "open", sPrg, vbNullString, 0&, SW_NORMAL)
    End Sub
    And if that doesn't work, you can always try the old standby

    Code:
    Private sub Command1_Click()
    
    Dim x as long
    
    x=Shell("c:\marcbrkr.exe",vbNormalFocus)
    
    end sub
    Good luck

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Posts
    29

    Thanx, that seems to work.

    The Shell works fine. Thank you all. Sniff Sniff. You all always seem to have JUST the right answer... I love you guys!
    Sorry for the outburst. Thanx/.

  5. #5
    Guest
    You can also use Options from a shell function.

    Code:
    Shell "Command.com edit /?", VbNormalFocus
    Or something like that ;].

    [Edited by Matthew Gates on 07-14-2000 at 09:21 PM]

  6. #6
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593

    Talking Yeah, Shell

    Yeah, the Shell command is pretty good. It works most like a DOS command line.

    Try this for fun some time (but make sure you don't have a file on the root called Files.txt that you need for anything):

    Code:
    Shell "dir c:\*.* /s/a/o/l/b > c:\files.txt"
    This is just a simple example, but it illustrates that most anything you can do from a DOS command line, you can do from within VB using the Shell command.

    Pretty useful for small tasks because it is quick and easy.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Posts
    29

    Angry Hmph, Now WHAT!?

    Hello Again.

    Well what seemed to work eariler no long works now. Even Basic DOS Command like the:

    "DIR *.*"

    Doesn't work correctly. Any suggestions? It worked fine yesterday, all I did was place the filenames and File Directories into Variables. Thinking this might have been the Problem I undid that...No change.

    Also, while I am here...

    I have a program that outputs something in DOS (Once again I did not make this one) and I want what it out put to appear in a Text Box. Is there a way to do this?

    Adios for now.

  8. #8
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    To run your DOS program and then read the results you should just send the output to a file and then read it in:
    Shell "yourprg.exe > somefile.txt"

    Then somefile.txt should store the output.
    "People who think they know everything are a great annoyance to those of us who do."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width