Launching DOS windows 
Author Message
 Launching DOS windows

Hi,
I'm trying to launch and run some DOS apps. Firstly, how do you specify a
directory to start in when you open a DOS window. Also how on earth do you
prevent the DOS window closing when the program has ended.
Any help would be much appreciated.
Regards,
Doug


Sun, 23 Sep 2001 03:00:00 GMT  
 Launching DOS windows

Quote:

>Hi,
>I'm trying to launch and run some DOS apps. Firstly, how do you specify a
>directory to start in when you open a DOS window. Also how on earth do you
>prevent the DOS window closing when the program has ended.
>Any help would be much appreciated.
>Regards,
>Doug

This snippet out of a module that launches a DOS creature called "smrtstat"
Filepath is a string containing the path

 retVal = Shell(FilePath & "\smrtstat.bat", vbNormalFocus)

Another section had to launch pkunzip

    If MsgBox("Use ZIP import?", vbQuestion + vbYesNo) = vbYes Then
        txtZip$ = "Command.com /C " & FilePath & "\pkunzip " & txtfiletoget$
& " " & FilePath & "\temp\ -o"
    Else
        txtZip$ = "Command.com /C " & FilePath & "\expand  " & txtfiletoget$
& " " & FilePath & "\temp\rspondnt.mdb"
    End If
    retVal = Shell(txtZip$, vbNormalFocus)

The /C terminates the DOS box after it completes

Have fun!



Sun, 23 Sep 2001 03:00:00 GMT  
 Launching DOS windows
Say you wanted to open the DOS window at Drive 'd:' and change to the
Directory 'temp' on Drive 'd:', then the following will do that:

Drv$ = "d:"
Pth$ = "\temp"
Shell Environ("comspec") & " /k " & _
          Drv$ & " | " & Environ("comspec") & _
          " /c cd "  & Pth$", vbNormalFocus

I split up the Shell statement so that your browser would display it
"funny". You can remove the underline characters and put it all on one line
or copy and paste it as is.

COMSPEC is the environmental variable that contains the command processor,
/k says keep the DOS window that is opened running, /c says (paraphrased)
execute command only, vbNormalFocus says let the focus stay on the opened
DOS window.

Rick

Quote:

>Hi,
>I'm trying to launch and run some DOS apps. Firstly, how do you specify a
>directory to start in when you open a DOS window. Also how on earth do you
>prevent the DOS window closing when the program has ended.
>Any help would be much appreciated.
>Regards,
>Doug



Sun, 23 Sep 2001 03:00:00 GMT  
 Launching DOS windows
Put following code in a form module

Private Const INFINITE = &HFFFF
Private Const SYNCHRONIZE = &H100000

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
As Long

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function GetLastError Lib "kernel32" () As Long

private sub Form_click()
    Dim pid as long
    dim   Somedrive  as string
    dim   SomeDir   as string
    dim   exeFileName   as string

    'assign name for drive, directory, and exe file name here

    chdrive  Somedrive
    chdir Somedir

    pid = Shell(exeFileName, vbHide)
    If pid <> 0 Then
            WaitForEndRun pid
    End If

end sub

Private Sub WaitForEndRun(pid As Long)
'This routine freezes the application

    Dim phnd As Long
    Dim WFO As Long
    Dim CHl As Long
    Dim ErrNo

    phnd = OpenProcess(SYNCHRONIZE, 0, pid)
    If phnd <> 0 Then
        WFO = WaitForSingleObject(phnd, INFINITE)
        CHl = CloseHandle(phnd)
        If CHl = 0 Then
            ErrNo = GetLastError()
            MsgBox ("Error: " & ErrNo)
        End If
    End If

End Sub


Quote:
> Say you wanted to open the DOS window at Drive 'd:' and change to the
> Directory 'temp' on Drive 'd:', then the following will do that:

> Drv$ = "d:"
> Pth$ = "\temp"
> Shell Environ("comspec") & " /k " & _
>           Drv$ & " | " & Environ("comspec") & _
>           " /c cd "  & Pth$", vbNormalFocus

> I split up the Shell statement so that your browser would display it
> "funny". You can remove the underline characters and put it all on one
line
> or copy and paste it as is.

> COMSPEC is the environmental variable that contains the command processor,
> /k says keep the DOS window that is opened running, /c says (paraphrased)
> execute command only, vbNormalFocus says let the focus stay on the opened
> DOS window.

> Rick


> >Hi,
> >I'm trying to launch and run some DOS apps. Firstly, how do you specify a
> >directory to start in when you open a DOS window. Also how on earth do
you
> >prevent the DOS window closing when the program has ended.
> >Any help would be much appreciated.
> >Regards,
> >Doug



Mon, 24 Sep 2001 03:00:00 GMT  
 Launching DOS windows
Doug
====
OK, I'm not sure where my head was when I wrote that convoluted Shell
statement. My original three lines can be replaced with

ChDrive "d:"
ChDir "\temp"
Shell Environ("comspec") & " /k", vbNormalFocus

where the '/k' keeps the window open. A lot shorter, huh?

Zhanchi
======
The reason I didn't go through all of the "wait to finish" coding is because
I though that Doug wanted the window opened so HE could execute various DOS
programs - not a set program. I concluded this because he asked: "Also how
on earth do you prevent the DOS window closing when the program has ended".
Perhaps I was wrong, only Doug knows sure. Thanks for reminding me of ChDir
and ChDrive - I'm not sure why I "forgot" them when composing my original
answer. I probably was trying to show how clever I was in constructing Shell
statements ;>)

Rick

Quote:

>Put following code in a form module

>Private Const INFINITE = &HFFFF
>Private Const SYNCHRONIZE = &H100000

>Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
>As Long

>Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
>As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

>Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
>As Long, ByVal dwMilliseconds As Long) As Long

>Private Declare Function GetLastError Lib "kernel32" () As Long

>private sub Form_click()
>    Dim pid as long
>    dim   Somedrive  as string
>    dim   SomeDir   as string
>    dim   exeFileName   as string

>    'assign name for drive, directory, and exe file name here

>    chdrive  Somedrive
>    chdir Somedir

>    pid = Shell(exeFileName, vbHide)
>    If pid <> 0 Then
>            WaitForEndRun pid
>    End If

>end sub

>Private Sub WaitForEndRun(pid As Long)
>'This routine freezes the application

>    Dim phnd As Long
>    Dim WFO As Long
>    Dim CHl As Long
>    Dim ErrNo

>    phnd = OpenProcess(SYNCHRONIZE, 0, pid)
>    If phnd <> 0 Then
>        WFO = WaitForSingleObject(phnd, INFINITE)
>        CHl = CloseHandle(phnd)
>        If CHl = 0 Then
>            ErrNo = GetLastError()
>            MsgBox ("Error: " & ErrNo)
>        End If
>    End If

>End Sub



>> Say you wanted to open the DOS window at Drive 'd:' and change to the
>> Directory 'temp' on Drive 'd:', then the following will do that:

>> Drv$ = "d:"
>> Pth$ = "\temp"
>> Shell Environ("comspec") & " /k " & _
>>           Drv$ & " | " & Environ("comspec") & _
>>           " /c cd "  & Pth$", vbNormalFocus

>> I split up the Shell statement so that your browser would display it
>> "funny". You can remove the underline characters and put it all on one
>line
>> or copy and paste it as is.

>> COMSPEC is the environmental variable that contains the command
processor,
>> /k says keep the DOS window that is opened running, /c says (paraphrased)
>> execute command only, vbNormalFocus says let the focus stay on the opened
>> DOS window.

>> Rick


>> >Hi,
>> >I'm trying to launch and run some DOS apps. Firstly, how do you specify
a
>> >directory to start in when you open a DOS window. Also how on earth do
>you
>> >prevent the DOS window closing when the program has ended.
>> >Any help would be much appreciated.
>> >Regards,
>> >Doug



Mon, 24 Sep 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Launching Windows Program from DOS Program

2. DOS or Windows DOS-box?

3. VBDOS Basic DOS using Timer in Windows DOS box

4. VBDOS Basic DOS using Timer in Windows DOS box

5. Help: hiding a DOS window when executing a DOS batch file

6. question on hiding a DOS window when executing a DOS batch file

7. Writing to stdout/DOS window from VB DOS exe

8. Dos command without opening DOS-PROMPT window ??

9. How To Capture Dos Output Without Opening Dos Window

10. Using Dos commands without dos window

11. NetBios/Dos Windows/Dos EXE properties

12. Launch Windows form, from a Windows Service Application

 

 
Powered by phpBB® Forum Software