Solved

Conformation after Shell process finished...

Posted on 2000-03-15
3
244 Views
Last Modified: 2010-05-02
I open standard executable file with Shell function from another application and I want  to receive conformation after executable finished all the auto processes in order to start next executable. Is there any other way besides creating new dll to manage everything?

0
Comment
Question by:GinaP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Expert Comment

by:hes
ID: 2621581
Place this in the declarations section of the project.

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

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

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

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



In your code:

Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

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

'Start the shelled application:
ret& = CreateProcessA(0&, "Your Batch File", 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)
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 35 total points
ID: 2621602
Yes.. what you want to do is a shell and wait.. ie.. run the program and wait until it is done until you continue processing. If you have VB6 and the "Windows Scripting Host" (it comes with Explorer" do the following:

1. Create a Standard.Exe Project.
2. Add a Project reference (Click on VB Menu.. Project.. References).. to "Windows Scripting Host Object"
3. Copy and paste the code below into the Form1 code window.
4. Change the strCommand variable below to the program you want to execute (its set for c:\windows\calc.exe for demo purposes)
5. Give it a run.. calc will open.. when you close it.. the program will continue.. <smile>.

<----- Code Begin ----->

Option Explicit
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3
Const SW_SHOWNOACTIVE = 4
Const SW_SHOW = 5
Const SW_MINIMIZE = 6
Const SW_SHOWMINNOACTIVE = 7
Const SW_SHOWNA = 8
Const SW_RESTORE = 9

Private Sub Form_Load()

  Dim strCommand As String
  strCommand = "c:\windows\calc.exe"

  Dim booWaitToFinish
  booWaitToFinish = True

  MsgBox ("About to run " & strCommand)

  Dim oShl As New IWshShell_Class
  Call oShl.Run(strCommand, SW_SHOWNORMAL, booWaitToFinish)
   
  Msgbox (strCommand & " COMPLETED!!!")

End Sub

<----- Code End ----->





0
 

Author Comment

by:GinaP
ID: 2623592
Thank you very much, wsh2. The answer is perfect. It works.
I appreciated the other answer also, just this one seems little simpler and shorter.
Thanks again.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

687 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