|
-
May 26th, 2005, 09:31 PM
#1
Thread Starter
Addicted Member
Synchronizing ShellExecute
I've looked all over the net trying to find a way to synchronize a program executed with ShellExecute, and all the code I've found fails. For some reason, any attempt to run my self-terminating command-line program, such as CreateProcessA and Shell fails, and only ShellExecute really works. The following code is the closest I could get to it, but CreateProcess fails, and ShellExecute doesn't return a handle:
VB Code:
'Declarations are omited to make it easier to read.
Public Function ShellSynchronous(cmdline As String) As Long
On Error GoTo ProcErr
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
Dim Count As Long
start.cb = Len(start)
ret = CreateProcessA(0, cmdline, 0, 0, 1, NORMAL_PRIORITY_CLASS, 0, 0, start, proc)
Count = GetTickCount
ret = WaitForSingleObject(proc.hProcess, INFINITE)
'If (GetTickCount - Count) < 1000 Then
' Sleep 1000
'End If
Call GetExitCodeProcess(proc.hProcess, ret)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ShellSynchronous = ret
Exit Function
ProcErr:
Err.Raise Err.Number
End Function
Please, put a checkmark (  ) or the word [RESOLVED] in your topic title if it was resolved, and rate the person who resolved it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|