LOST CONTROl OVER MSDOS BATCH FILE 
Author Message
 LOST CONTROl OVER MSDOS BATCH FILE

I have a problem in executing MS-DOS batch files within Visual Basic. My
problem is I dont want to continue executing my visual basic code till  all
the commands in the batch files executed. Is there anyway to resume
execution only after the completion of Batchfile Execution.

Thanks in advance,

Saju Sukumar



Sat, 30 Aug 2003 16:49:09 GMT  
 LOST CONTROl OVER MSDOS BATCH FILE
Hi,

The following code will work.   Sorry i cant describe how it works exactly,
but it suited my needs.

Public Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

Public Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
End Type

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

Public Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As _
String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, lpStartupInfo As _
STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
As Long

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

Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&

Public Sub ExecCmd(cmdLine As String)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret&

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
ret& = CreateProcessA(0&, cmdLine$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub


Quote:
> I have a problem in executing MS-DOS batch files within Visual Basic. My
> problem is I dont want to continue executing my visual basic code till
all
> the commands in the batch files executed. Is there anyway to resume
> execution only after the completion of Batchfile Execution.

> Thanks in advance,

> Saju Sukumar



Mon, 01 Sep 2003 07:45:45 GMT  
 LOST CONTROl OVER MSDOS BATCH FILE
Thank you very much...it does work exactly the way I want to be....

Saju Sukumar


Quote:
> Hi,

> The following code will work.   Sorry i cant describe how it works
exactly,
> but it suited my needs.

> Public Type STARTUPINFO
>     cb As Long
>     lpReserved As String
>     lpDesktop As String
>     lpTitle As String
>     dwX As Long
>     dwY As Long
>     dwXSize As Long
>     dwYSize As Long
>     dwXCountChars As Long
>     dwYCountChars As Long
>     dwFillAttribute As Long
>     dwFlags As Long
>     wShowWindow As Integer
>     cbReserved2 As Integer
>     lpReserved2 As Long
>     hStdInput As Long
>     hStdOutput As Long
>     hStdError As Long
> End Type

> Public Type PROCESS_INFORMATION
>     hProcess As Long
>     hThread As Long
>     dwProcessID As Long
>     dwThreadID As Long
> End Type

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

> Public Declare Function CreateProcessA Lib "kernel32" _
> (ByVal lpApplicationName As Long, ByVal lpCommandLine As _
> String, ByVal lpProcessAttributes As Long, ByVal _
> lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
> ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
> ByVal lpCurrentDirectory As Long, lpStartupInfo As _
> STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
> As Long

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

> Public Const NORMAL_PRIORITY_CLASS = &H20&
> Public Const INFINITE = -1&

> Public Sub ExecCmd(cmdLine As String)
> Dim proc As PROCESS_INFORMATION
> Dim start As STARTUPINFO
> Dim ret&

> ' Initialize the STARTUPINFO structure:
> start.cb = Len(start)

> ' Start the shelled application:
> ret& = CreateProcessA(0&, cmdLine$, 0&, 0&, 1&, _
> NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

> ' Wait for the shelled application to finish:
> ret& = WaitForSingleObject(proc.hProcess, INFINITE)
> ret& = CloseHandle(proc.hProcess)
> End Sub



> > I have a problem in executing MS-DOS batch files within Visual Basic. My
> > problem is I dont want to continue executing my visual basic code till
> all
> > the commands in the batch files executed. Is there anyway to resume
> > execution only after the completion of Batchfile Execution.

> > Thanks in advance,

> > Saju Sukumar



Thu, 04 Sep 2003 14:34:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. LOST CONTROL OVER MSDOS BATCH FILE

2. DOS Batch File to Copy Files from an Access Application

3. Bad Command or File name when Shelling DOS Batch File

4. need batch file way to make Word97 convert a file

5. file compare inside a batch file

6. How do you pass parameters from a batch file to a VBS file

7. Running batch file from asp file

8. how to execute a batch file into a VBS file

9. Logon Batch to call a VBS that calls another batch

10. Coded Events lost link to Control when copying to a Tab Control

11. Keypreview Lost When Using a User Control embedded in another user control

12. Calling Batch file

 

 
Powered by phpBB® Forum Software