|
|
|
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: |
To test this function, write the following code in your form (it assumes that Notepad is on your system path): |
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 ) |
|
|