Solved

Conformation after Shell process finished...

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 / DAO 3.6 / run time error: Couldn't find installable ISAM 7 94
MsgBox 4 59
Problem to With line 4 57
Error with a code discussed on this page 5 12
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 …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

785 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