Solved

Conformation after Shell process finished...

Posted on 2000-03-15
3
238 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
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

707 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

18 Experts available now in Live!

Get 1:1 Help Now