Solved

Shelling to a DOS app in VB 5

Posted on 1998-07-22
4
165 Views
Last Modified: 2010-05-03
I'm using a SHELL command to run a DOS application from VB5.
What I need to know is how to determine when the shelled app has completed running.
I've tried using FindWindow (as in previous versions of VB) but this doesn't pick up on the fact that the app is still running.
0
Comment
Question by:marcus_m1
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Dalin
ID: 1466423
marcus_m1

Check it out:
http://support.microsoft.com/support/kb/articles/q96/8/44.asp
HOWTO: Determine When a Shelled Process Has Terminated.

Regards
Dalin
0
 

Author Comment

by:marcus_m1
ID: 1466424
Thanks Dalin for the quick response, but believe me I have tried this.
This method works fine in 16 bit VB apps, but I'm coding a 32 bit app.
0
 
LVL 7

Accepted Solution

by:
tward earned 50 total points
ID: 1466425
This will do it for you in 32 bit:

Option Explicit

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

Private 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

Private Type PROCESS_INFORMATION
       
       hProcess As Long
       hThread As Long
       dwProcessID As Long
       dwThreadID As Long

End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private 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
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Sub msiShellAndWait(ByVal CommandLine As String)

  Dim ReturnValue As Long
  Dim Start As STARTUPINFO
  Dim Process As PROCESS_INFORMATION

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

  ' Start the shelled application:
  ReturnValue = CreateProcessA(0&, CommandLine, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, Start, Process)

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

0
 

Author Comment

by:marcus_m1
ID: 1466426
Thanks tward,

I've tried your suggestion and it works perfectly.

Marcus
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA/SQL - Connect to SQL server and pull data 4 88
VBA filters 2 50
Notepad++ how to remove delimiter : from beggning of the line? 3 93
How to Add / Edit Windows Menu 4 51
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now