Solved

Conformation after Shell process finished...

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

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now