Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute!!! 2

Status
Not open for further replies.

vbkris

Programmer
Joined
Jan 20, 2003
Messages
5,994
Location
IN
hi,
i have a shell execute command likeso:
sub main()
m=ShellExecute(0,"open",Path,"",App.path,3)
end sub

this project has only the module file (no forms). it simply opens a exe file (flash generated).

i want the application to stay active until someone closes the flash file that is opened using shellexecute. is that possible?
right now the flash file opens, but my vb project ends...

Known is handfull, Unknown is worldfull
 
I got this off the site some time ago - maybe it will help:

This is kind of interesting in that it is a piece of code that allows you to shell another app but then will pause until the shelled program has finished.


Option Explicit

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = -1&
'-----------------------------------------------------------
Sub Main()
Dim sPrgm As String

sPrgm = "C:\Winnt\notepad.exe"

RunUntilFinished sPrgm

MsgBox "App is finished!"

End
End Sub
'-----------------------------------------------------------
Public Sub RunUntilFinished(ByVal sApp As String)
Dim lProcID As Long
Dim hProc As Long

' Start the App
On Error GoTo ErrHndlr
lProcID = Shell(sApp, vbNormalFocus)
On Error GoTo 0

DoEvents

' Wait for the App
hProc = OpenProcess(SYNCHRONIZE, 0, lProcID)
If hProc <> 0 Then
WaitForSingleObject hProc, INFINITE
CloseHandle hProc
End If
Exit Sub

ErrHndlr:
MsgBox &quot;Error starting App:&quot; & vbCrLf & _
&quot;App: &quot; & sApp & vbCrLf & _
&quot;Err Desc: &quot; & Err.Description
Err.Clear
End Sub
 
Awesome!!!

but paul ur CloseHadle gave me an error...

Known is handfull, Unknown is worldfull
 
vbkris,

If you look down the thread I linked to, I posted the Close handle function in a separate message. Sorry about that!

Public Declare Function CloseHandle Lib &quot;kernel32.dll&quot; _
(ByVal hObject As Long) As Long


Paul Bent
Northwind IT Systems
 
do i need that? beacuse it seems to be working without the closehandle thing...

Known is handfull, Unknown is worldfull
 

vbkris,

Yes you need to use the CloseHandle API when you are done because you can cause memory leaks of your program if you don't.

Good Luck

 
thanks...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top