Hi,
I'm using winrar to rar/unrar archives in vba using ShellAndWaitForTermination.
This works, but now I would like to know when the archive is valid using the T command. How do I get the return value of that command?Code:Public Function ShellAndWaitForTermination( _ sShell As String, _ Optional ByVal eWindowStyle As VBA.VbAppWinStyle = vbNormalFocus, _ Optional ByRef sError As String, _ Optional ByVal lTimeOut As Long = 2000000000 _ ) As Boolean Dim hProcess As Long Dim lR As Long Dim lTimeStart As Long Dim bSuccess As Boolean On Error GoTo ShellAndWaitForTerminationError ' This is v2 which is somewhat more reliable: hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(sShell, eWindowStyle)) If (hProcess = 0) Then sError = "This program could not determine whether the process started." & _ "Please watch the program and check it completes." ' Only fail if there is an error - this can happen ' when the program completes too quickly. Else bSuccess = True lTimeStart = timeGetTime() Do ' Get the status of the process GetExitCodeProcess hProcess, lR ' Sleep during wait to ensure the other process gets ' processor slice: DoEvents: Sleep 100 If (timeGetTime() - lTimeStart > lTimeOut) Then ' Too long! sError = "The process has timed out." lR = 0 bSuccess = False End If Loop While lR = STILL_ACTIVE End If ShellAndWaitForTermination = bSuccess Exit Function ShellAndWaitForTerminationError: MsgBox err.Description sError = err.Description Exit Function End Function
Is it at all possible to get a return value from a process?
Stef


LinkBack URL
About LinkBacks






Reply With Quote