Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Wait for the termination of a program using Windows Scripting Host
[ All Languages » VB »  Windows]

Total Hit ( 2708)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


If you want to execute an application and waiting for its termination, you can follow two approaches. The "classic" approach is based on API functions such as OpenProcess, WaitForSingleObject and CloseHandle. However, there is a simpler technique based on the Windows Scripting Host object model.

A method exposed by this library lets you to run a file, and specify whether you want to wait for its termination. To use the following code snippet you must add a reference to Windows Scripting Host Object model in the "References " dialog window. The method you're looking for is the Run method of the IWshShell_Class object. Its first argument is the file to run, the second specifies the styles of the application's window and the last is a Boolean value that tells whether you want to wait for the program termination. Here's a function that contains all the necessary code:

Click here to copy the following block
Sub RunAndWait(ByVal sFile As String)
  Dim WSHShell As New IWshShell_Class
  WSHShell.Run sFile, , True
End Sub

To test this function, write the following code in your form (it assumes that Notepad is on your system path):

Click here to copy the following block
Private Sub Form_Click()
  RunAndWait "notepad.exe"
  MsgBox "Back to your application!"
End Sub

You'll see that the message box will appear only when you close Notepad.



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.